class TieredCaching::RedisStore
Constants
- GETSET_PATH
- GETSET_SCRIPT
Public Class Methods
new(connection)
click to toggle source
# File lib/tiered_caching/redis_store.rb, line 11 def initialize(connection) @connection = connection @active_connection = @connection end
Public Instance Methods
get(key)
click to toggle source
# File lib/tiered_caching/redis_store.rb, line 21 def get(key) with_connection(:get) { |connection| connection.get(key) } end
getset(key) { |])| ... }
click to toggle source
# File lib/tiered_caching/redis_store.rb, line 25 def getset(key) with_connection(:getset) do |connection| @getset_sha ||= connection.script(:load, GETSET_SCRIPT) connection.evalsha(@getset_sha, keys: [key], argv: [yield]) end end
set(key, value)
click to toggle source
# File lib/tiered_caching/redis_store.rb, line 16 def set(key, value) with_connection(:set) { |connection| connection.set(key, value) } value end
Private Instance Methods
with_connection(action) { |active_connection| ... }
click to toggle source
# File lib/tiered_caching/redis_store.rb, line 34 def with_connection(action) if @disconnect_time if Time.now >= (@disconnect_time + 5) @active_connection = @connection end end if @active_connection begin yield @active_connection rescue => e Logging.logger.warn("Error calling ##{action} on redis store: #{e}") @active_connection = nil @getset_sha = nil @disconnect_time = Time.now nil end end end