Class: RedisConnection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

#createdObject

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

#closeObject



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.

Returns:

  • (Boolean)


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_timeoutObject

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

#openObject



16
17
18
# File 'lib/cache_store_redis/redis_connection.rb', line 16

def open
  self.created = Time.now if self.created.nil?
end