Class: Docket::Storage::Redis
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #append(key, value) ⇒ Object
- #clear! ⇒ Object
- #describe ⇒ Object
-
#initialize(options = {}) ⇒ Redis
constructor
A new instance of Redis.
- #read(key) ⇒ Object
- #remove(key) ⇒ Object
- #save(key, value, options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Redis
Returns a new instance of Redis.
8 9 10 11 |
# File 'lib/docket/storage/redis.rb', line 8 def initialize ={} super self.db = [:redis] || ::Redis.new end |
Instance Method Details
#append(key, value) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/docket/storage/redis.rb', line 17 def append key, value if read(key).nil? save(key, Array(value)) else current = read(key) new_value = Array(current) << value save(key, new_value.uniq) end end |
#clear! ⇒ Object
35 36 37 38 |
# File 'lib/docket/storage/redis.rb', line 35 def clear! keys = keys_context redis.del(*keys) unless keys.empty? end |
#describe ⇒ Object
40 41 42 43 44 |
# File 'lib/docket/storage/redis.rb', line 40 def describe keys_context.map do |key| [key, read(clean(key))] end end |
#read(key) ⇒ Object
31 32 33 |
# File 'lib/docket/storage/redis.rb', line 31 def read key read_packed key end |
#remove(key) ⇒ Object
27 28 29 |
# File 'lib/docket/storage/redis.rb', line 27 def remove key redis.del(namespaced(key)) end |
#save(key, value, options = {}) ⇒ Object
13 14 15 |
# File 'lib/docket/storage/redis.rb', line 13 def save key, value, ={} save_packed key, value end |