Class: Faye::Redis::Connection
- Inherits:
-
Object
- Object
- Faye::Redis::Connection
- Defined in:
- lib/faye/redis/connection.rb
Defined Under Namespace
Classes: ConnectionError
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#connected? ⇒ Boolean
Check if connected to Redis.
-
#create_pubsub_connection ⇒ Object
Get a dedicated Redis connection for pub/sub (not from pool).
-
#disconnect ⇒ Object
Disconnect from Redis.
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
-
#ping ⇒ Object
Ping Redis server.
-
#with_redis(&block) ⇒ Object
Execute a Redis command with connection pooling.
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 = @pool = create_connection_pool end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/faye/redis/connection.rb', line 9 def @options end |
Instance Method Details
#connected? ⇒ Boolean
Check if connected to Redis
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_connection ⇒ Object
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 |
#disconnect ⇒ Object
Disconnect from Redis
36 37 38 |
# File 'lib/faye/redis/connection.rb', line 36 def disconnect @pool.shutdown { |redis| redis.quit rescue nil } end |
#ping ⇒ Object
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 |