Class: Metacrunch::Redis::QueueDestination
- Inherits:
-
Object
- Object
- Metacrunch::Redis::QueueDestination
- Defined in:
- lib/metacrunch/redis/queue_destination.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(redis_connection_or_url, queue_name, options = {}) ⇒ QueueDestination
constructor
A new instance of QueueDestination.
- #write(data) ⇒ Object
Constructor Details
#initialize(redis_connection_or_url, queue_name, options = {}) ⇒ QueueDestination
Returns a new instance of QueueDestination.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/metacrunch/redis/queue_destination.rb', line 6 def initialize(redis_connection_or_url, queue_name, = {}) @queue_name = queue_name raise ArgumentError, "queue_name must be a string" unless queue_name.is_a?(String) @save_on_close = .delete(:save_on_close) || true @redis = if redis_connection_or_url.is_a?(String) ::Redis.new(url: redis_connection_or_url) else redis_connection_or_url end end |
Instance Method Details
#close ⇒ Object
31 32 33 34 35 36 |
# File 'lib/metacrunch/redis/queue_destination.rb', line 31 def close if @redis @redis.bgsave if @save_on_close @redis.close end end |
#write(data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/metacrunch/redis/queue_destination.rb', line 19 def write(data) @redis.rpush(@queue_name, data) rescue RuntimeError => e if e. =~ /maxmemory/ puts "Redis has reached maxmemory. Waiting 10 seconds and trying again..." sleep(10) retry else raise e end end |