lib/basket/backend_adapter/redis_backend.rb in basket-0.0.3 vs lib/basket/backend_adapter/redis_backend.rb in basket-0.0.4

- old
+ new

@@ -4,15 +4,11 @@ class BackendAdapter class RedisBackend < Basket::BackendAdapter attr_reader :client def initialize - redis_connection = Redis.new( - host: Basket.config.redis_host, - port: Basket.config.redis_port, - db: Basket.config.redis_db - ) + redis_connection = select_redis_connection @client = Redis::Namespace.new( Basket.config.namespace, redis: redis_connection ) @@ -48,9 +44,31 @@ private def deserialized_queue_data(queue) @client.lrange(queue, 0, -1).reverse.map { |marshalled_data| Marshal.load(marshalled_data) } + end + + def select_redis_connection + if Basket.config.redis_url + redis_connection_from_url + else + redis_connection_from_host + end + end + + def redis_connection_from_host + Redis.new( + host: Basket.config.redis_host, + port: Basket.config.redis_port, + db: Basket.config.redis_db + ) + end + + def redis_connection_from_url + Redis.new( + url: Basket.config.redis_url + ) end end end end