Class: RedisQueue::RedisConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ RedisConnection

Returns a new instance of RedisConnection.



4
5
6
# File 'lib/redis_connection.rb', line 4

def initialize(args)
  @args = args
end

Instance Method Details

#new_redisObject



22
23
24
# File 'lib/redis_connection.rb', line 22

def new_redis
  ::Redis.new(@args)
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/redis_connection.rb', line 8

def run
  @redis ||= new_redis

  begin
    yield(@redis)
  rescue Redis::CannotConnectError, Redis::TimeoutError => e
    puts e.backtrace
    puts 'Redis crashed, retrying'
    sleep 2
    @redis = new_redis
    retry
  end
end