lib/basket/backend_adapter/redis_backend.rb in basket-0.0.5 vs lib/basket/backend_adapter/redis_backend.rb in basket-0.0.6
- old
+ new
@@ -1,6 +1,7 @@
require "redis-namespace"
+require "json"
module Basket
class BackendAdapter
class RedisBackend < Basket::BackendAdapter
attr_reader :client
@@ -23,13 +24,11 @@
response
end
def push(queue, data)
- # TODO: should we use JSON vs Marshal?
- marshalled_data = Marshal.dump(data)
- @client.lpush(queue, marshalled_data)
+ @client.lpush(queue, serialize_data(data))
end
def length(queue)
@client.llen(queue)
end
@@ -42,11 +41,15 @@
deserialized_queue_data(queue)
end
private
+ def serialize_data(data)
+ JSON.generate(data)
+ end
+
def deserialized_queue_data(queue)
- @client.lrange(queue, 0, -1).reverse.map { |marshalled_data| Marshal.load(marshalled_data) }
+ @client.lrange(queue, 0, -1).reverse.map { |serialized_data| JSON.parse(serialized_data) }
end
def select_redis_connection
if Basket.config.redis_url
redis_connection_from_url