Class: TieredCaching::RedisStore
- Inherits:
-
Object
- Object
- TieredCaching::RedisStore
- Extended by:
- Forwardable
- Defined in:
- lib/tiered_caching/redis_store.rb
Constant Summary collapse
- GETSET_PATH =
File.join(TieredCaching.root, 'tiered_caching/redis_store/getset.lua')
- GETSET_SCRIPT =
File.read(GETSET_PATH)
Instance Method Summary collapse
- #get(key) ⇒ Object
- #getset(key) ⇒ Object
-
#initialize(connection) ⇒ RedisStore
constructor
A new instance of RedisStore.
- #set(key, value) ⇒ Object
Constructor Details
#initialize(connection) ⇒ RedisStore
Returns a new instance of RedisStore.
11 12 13 14 |
# File 'lib/tiered_caching/redis_store.rb', line 11 def initialize(connection) @connection = connection @active_connection = @connection end |
Instance Method Details
#get(key) ⇒ Object
21 22 23 |
# File 'lib/tiered_caching/redis_store.rb', line 21 def get(key) with_connection(:get) { |connection| connection.get(key) } end |
#getset(key) ⇒ Object
25 26 27 28 29 30 |
# 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) ⇒ Object
16 17 18 19 |
# File 'lib/tiered_caching/redis_store.rb', line 16 def set(key, value) with_connection(:set) { |connection| connection.set(key, value) } value end |