Class: Faye::Redis::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/faye/redis/connection.rb

Defined Under Namespace

Classes: ConnectionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



11
12
13
14
# File 'lib/faye/redis/connection.rb', line 11

def initialize(options = {})
  @options = options
  @pool = create_connection_pool
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/faye/redis/connection.rb', line 9

def options
  @options
end

Instance Method Details

#connected?Boolean

Check if connected to Redis

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/faye/redis/connection.rb', line 24

def connected?
  with_redis { |redis| redis.ping == 'PONG' }
rescue ::Redis::CannotConnectError, ::Redis::ConnectionError, ::Redis::TimeoutError, Faye::Redis::Connection::ConnectionError, EOFError => e
  false
end

#create_pubsub_connectionObject

Get a dedicated Redis connection for pub/sub (not from pool)



41
42
43
# File 'lib/faye/redis/connection.rb', line 41

def create_pubsub_connection
  create_redis_client
end

#disconnectObject

Disconnect from Redis



36
37
38
# File 'lib/faye/redis/connection.rb', line 36

def disconnect
  @pool.shutdown { |redis| redis.quit rescue nil }
end

#pingObject

Ping Redis server



31
32
33
# File 'lib/faye/redis/connection.rb', line 31

def ping
  with_redis { |redis| redis.ping }
end

#with_redis(&block) ⇒ Object

Execute a Redis command with connection pooling



17
18
19
20
21
# File 'lib/faye/redis/connection.rb', line 17

def with_redis(&block)
  with_retry do
    @pool.with(&block)
  end
end