lib/basket/backend_adapter/redis_backend.rb in basket-0.0.6 vs lib/basket/backend_adapter/redis_backend.rb in basket-0.0.7

- old
+ new

@@ -1,7 +1,6 @@ require "redis-namespace" -require "json" module Basket class BackendAdapter class RedisBackend < Basket::BackendAdapter attr_reader :client @@ -21,9 +20,21 @@ @client.scan_each do |queue| response[queue] = deserialized_queue_data(queue) end response + end + + def search(queue, &block) + deserialized_queue_data(queue).select { |raw_element| block.call(raw_element["data"]) } + end + + 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 def push(queue, data) @client.lpush(queue, serialize_data(data)) end