Class: RedisConnection
- Inherits:
-
Object
- Object
- RedisConnection
- Defined in:
- lib/cache_store_redis/redis_connection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#created ⇒ Object
Returns the value of attribute created.
Instance Method Summary collapse
- #close ⇒ Object
-
#expired? ⇒ Boolean
This method is called to determine if this connection has been open for longer than the keep alive timeout or not.
-
#initialize(config) ⇒ RedisConnection
constructor
A new instance of RedisConnection.
-
#keep_alive_timeout ⇒ Object
This method is called to get the keep alive timeout value to use for this connection.
- #open ⇒ Object
Constructor Details
#initialize(config) ⇒ RedisConnection
Returns a new instance of RedisConnection.
5 6 7 8 |
# File 'lib/cache_store_redis/redis_connection.rb', line 5 def initialize(config) self.client = Redis.new(config) self.created = Time.now end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/cache_store_redis/redis_connection.rb', line 3 def client @client end |
#created ⇒ Object
Returns the value of attribute created.
2 3 4 |
# File 'lib/cache_store_redis/redis_connection.rb', line 2 def created @created end |
Instance Method Details
#close ⇒ Object
20 21 22 23 |
# File 'lib/cache_store_redis/redis_connection.rb', line 20 def close self.client.close self.created = nil end |
#expired? ⇒ Boolean
This method is called to determine if this connection has been open for longer than the keep alive timeout or not.
11 12 13 14 |
# File 'lib/cache_store_redis/redis_connection.rb', line 11 def expired? return false if self.created.nil? Time.now >= (self.created + keep_alive_timeout) end |
#keep_alive_timeout ⇒ Object
This method is called to get the keep alive timeout value to use for this connection.
26 27 28 |
# File 'lib/cache_store_redis/redis_connection.rb', line 26 def keep_alive_timeout Float(ENV['REDIS_KEEP_ALIVE_TIMEOUT'] || 30) end |
#open ⇒ Object
16 17 18 |
# File 'lib/cache_store_redis/redis_connection.rb', line 16 def open self.created = Time.now if self.created.nil? end |