Class: Basket::BackendAdapter::RedisBackend
- Inherits:
-
Basket::BackendAdapter
- Object
- Basket::BackendAdapter
- Basket::BackendAdapter::RedisBackend
- Defined in:
- lib/basket/backend_adapter/redis_backend.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #clear(queue) ⇒ Object
- #data ⇒ Object
-
#initialize ⇒ RedisBackend
constructor
A new instance of RedisBackend.
- #length(queue) ⇒ Object
- #push(queue, data) ⇒ Object
- #read(queue) ⇒ Object
- #remove(queue, element_id) ⇒ Object
- #search(queue, &block) ⇒ Object
Constructor Details
#initialize ⇒ RedisBackend
Returns a new instance of RedisBackend.
8 9 10 11 12 13 14 15 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 8 def initialize redis_connection = select_redis_connection @client = Redis::Namespace.new( Basket.config.namespace, redis: redis_connection ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 6 def client @client end |
Instance Method Details
#clear(queue) ⇒ Object
47 48 49 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 47 def clear(queue) @client.del(queue) end |
#data ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 17 def data response = {} @client.scan_each do |queue| response[queue] = deserialized_queue_data(queue) end response end |
#length(queue) ⇒ Object
43 44 45 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 43 def length(queue) @client.llen(queue) end |
#push(queue, data) ⇒ Object
39 40 41 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 39 def push(queue, data) @client.lpush(queue, serialize_data(data)) end |
#read(queue) ⇒ Object
51 52 53 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 51 def read(queue) deserialized_queue_data(queue) end |
#remove(queue, element_id) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 31 def remove(queue, element_id) element = deserialized_queue_data(queue).find { |raw_element| raw_element["id"] == element_id } @client.lrem(queue, 1, element.to_json) element end |
#search(queue, &block) ⇒ Object
27 28 29 |
# File 'lib/basket/backend_adapter/redis_backend.rb', line 27 def search(queue, &block) deserialized_queue_data(queue).select { |raw_element| block.call(raw_element["data"]) } end |