Class: Workerholic::Storage::RedisWrapper
- Inherits:
-
Object
- Object
- Workerholic::Storage::RedisWrapper
show all
- Defined in:
- lib/workerholic/storage.rb
Defined Under Namespace
Classes: RedisCannotRecover
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_to_set(key, score, value, retry_delay = 5) ⇒ Object
-
#delete(key, retry_delay = 5) ⇒ Object
-
#fetch_queue_names(retry_delay = 5) ⇒ Object
-
#get_all_elements_from_list(key, retry_delay = 5) ⇒ Object
-
#get_keys_for_namespace(namespace, retry_delay = 5) ⇒ Object
-
#hash_get(key, field, retry_delay = 5) ⇒ Object
-
#hash_get_all(key, retry_delay = 5) ⇒ Object
-
#hash_get_multiple_elements(key, fields, retry_delay = 5) ⇒ Object
-
#hash_increment_field(key, field, increment, retry_delay = 5) ⇒ Object
-
#hash_keys(namespace, retry_delay = 5) ⇒ Object
-
#hash_set(key, field, value, retry_delay = 5) ⇒ Object
-
#initialize ⇒ RedisWrapper
constructor
A new instance of RedisWrapper.
-
#keys_count(namespace, retry_delay = 5) ⇒ Object
-
#list_length(key, retry_delay = 5) ⇒ Object
-
#peek(key, retry_delay = 5) ⇒ Object
-
#pop(key, timeout = 1, retry_delay = 5) ⇒ Object
blocking pop from Redis queue.
-
#push(key, value, retry_delay = 5) ⇒ Object
-
#remove_from_set(key, score, retry_delay = 5) ⇒ Object
-
#remove_range_from_set(key, minscore, maxscore, retry_delay = 5) ⇒ Object
-
#sorted_set_all_members(key, retry_delay = 5) ⇒ Object
-
#sorted_set_range_members(key, minscore, maxscore, retry_delay = 5) ⇒ Object
-
#sorted_set_size(key, retry_delay = 5) ⇒ Object
Constructor Details
Returns a new instance of RedisWrapper.
6
7
8
9
10
11
12
13
|
# File 'lib/workerholic/storage.rb', line 6
def initialize
@retries = 0
@redis = Workerholic.redis_pool
redis.with do |conn|
conn.ping
end
end
|
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis.
4
5
6
|
# File 'lib/workerholic/storage.rb', line 4
def redis
@redis
end
|
#retries ⇒ Object
Returns the value of attribute retries.
4
5
6
|
# File 'lib/workerholic/storage.rb', line 4
def retries
@retries
end
|
Instance Method Details
#add_to_set(key, score, value, retry_delay = 5) ⇒ Object
56
57
58
|
# File 'lib/workerholic/storage.rb', line 56
def add_to_set(key, score, value, retry_delay = 5)
execute(retry_delay) { |conn| conn.zadd(key, score, value) }
end
|
#delete(key, retry_delay = 5) ⇒ Object
39
40
41
|
# File 'lib/workerholic/storage.rb', line 39
def delete(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.del(key) }
end
|
#fetch_queue_names(retry_delay = 5) ⇒ Object
88
89
90
91
92
|
# File 'lib/workerholic/storage.rb', line 88
def fetch_queue_names(retry_delay = 5)
queue_name_pattern = 'workerholic:queue:*'
execute(retry_delay) { |conn| conn.keys(queue_name_pattern) }
end
|
#get_all_elements_from_list(key, retry_delay = 5) ⇒ Object
98
99
100
|
# File 'lib/workerholic/storage.rb', line 98
def get_all_elements_from_list(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.lrange(key, 0, -1) }
end
|
#get_keys_for_namespace(namespace, retry_delay = 5) ⇒ Object
94
95
96
|
# File 'lib/workerholic/storage.rb', line 94
def get_keys_for_namespace(namespace, retry_delay = 5)
execute(retry_delay) { |conn| conn.keys(namespace) }
end
|
#hash_get(key, field, retry_delay = 5) ⇒ Object
19
20
21
|
# File 'lib/workerholic/storage.rb', line 19
def hash_get(key, field, retry_delay = 5)
execute(retry_delay) { |conn| conn.hget(key, field) }
end
|
#hash_get_all(key, retry_delay = 5) ⇒ Object
23
24
25
|
# File 'lib/workerholic/storage.rb', line 23
def hash_get_all(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.hgetall(key) }
end
|
#hash_get_multiple_elements(key, fields, retry_delay = 5) ⇒ Object
31
32
33
|
# File 'lib/workerholic/storage.rb', line 31
def hash_get_multiple_elements(key, fields, retry_delay = 5)
execute(retry_delay) { |conn| conn.hmget(key, *fields) }
end
|
#hash_increment_field(key, field, increment, retry_delay = 5) ⇒ Object
35
36
37
|
# File 'lib/workerholic/storage.rb', line 35
def hash_increment_field(key, field, increment, retry_delay = 5)
execute(retry_delay) { |conn| conn.hincrby(key, field, increment) }
end
|
#hash_keys(namespace, retry_delay = 5) ⇒ Object
27
28
29
|
# File 'lib/workerholic/storage.rb', line 27
def hash_keys(namespace, retry_delay = 5)
execute(retry_delay) { |conn| conn.hkeys(namespace) }
end
|
#hash_set(key, field, value, retry_delay = 5) ⇒ Object
15
16
17
|
# File 'lib/workerholic/storage.rb', line 15
def hash_set(key, field, value, retry_delay = 5)
execute(retry_delay) { |conn| conn.hset(key, field, value) }
end
|
#keys_count(namespace, retry_delay = 5) ⇒ Object
84
85
86
|
# File 'lib/workerholic/storage.rb', line 84
def keys_count(namespace, retry_delay = 5)
execute(retry_delay) { |conn| conn.keys(namespace + ':*').size }
end
|
#list_length(key, retry_delay = 5) ⇒ Object
43
44
45
|
# File 'lib/workerholic/storage.rb', line 43
def list_length(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.llen(key) }
end
|
#peek(key, retry_delay = 5) ⇒ Object
60
61
62
|
# File 'lib/workerholic/storage.rb', line 60
def peek(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.zrange(key, 0, 0, with_scores: true).first }
end
|
#pop(key, timeout = 1, retry_delay = 5) ⇒ Object
blocking pop from Redis queue
52
53
54
|
# File 'lib/workerholic/storage.rb', line 52
def pop(key, timeout = 1, retry_delay = 5)
execute(retry_delay) { |conn| conn.blpop(key, timeout) }
end
|
#push(key, value, retry_delay = 5) ⇒ Object
47
48
49
|
# File 'lib/workerholic/storage.rb', line 47
def push(key, value, retry_delay = 5)
execute(retry_delay) { |conn| conn.rpush(key, value) }
end
|
#remove_from_set(key, score, retry_delay = 5) ⇒ Object
64
65
66
|
# File 'lib/workerholic/storage.rb', line 64
def remove_from_set(key, score, retry_delay = 5)
execute(retry_delay) { |conn| conn.zremrangebyscore(key, score, score) }
end
|
#remove_range_from_set(key, minscore, maxscore, retry_delay = 5) ⇒ Object
80
81
82
|
# File 'lib/workerholic/storage.rb', line 80
def remove_range_from_set(key, minscore, maxscore, retry_delay = 5)
execute(retry_delay) { |conn| conn.zremrangebyscore(key, minscore, maxscore) }
end
|
#sorted_set_all_members(key, retry_delay = 5) ⇒ Object
72
73
74
|
# File 'lib/workerholic/storage.rb', line 72
def sorted_set_all_members(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.zrange(key, 0, -1) }
end
|
#sorted_set_range_members(key, minscore, maxscore, retry_delay = 5) ⇒ Object
76
77
78
|
# File 'lib/workerholic/storage.rb', line 76
def sorted_set_range_members(key, minscore, maxscore, retry_delay = 5)
execute(retry_delay) { |conn| conn.zrangebyscore(key, minscore, maxscore, with_scores: true) }
end
|
#sorted_set_size(key, retry_delay = 5) ⇒ Object
68
69
70
|
# File 'lib/workerholic/storage.rb', line 68
def sorted_set_size(key, retry_delay = 5)
execute(retry_delay) { |conn| conn.zcard(key) }
end
|