Class: Taupe::Cache::RedisDriver
- Inherits:
-
Object
- Object
- Taupe::Cache::RedisDriver
- Defined in:
- lib/taupe/cache/redis.rb
Overview
Redis cache driver
Instance Attribute Summary collapse
-
#connection ⇒ Object
Accessors.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
Delete a key.
-
#get(key) ⇒ Object
Get a cache entry.
-
#initialize(dsn) ⇒ RedisDriver
constructor
Constructor.
-
#set(key, value) ⇒ Object
Set a cache entry.
Constructor Details
#initialize(dsn) ⇒ RedisDriver
Constructor
15 16 17 |
# File 'lib/taupe/cache/redis.rb', line 15 def initialize(dsn) @connection = Redis.new dsn end |
Instance Attribute Details
#connection ⇒ Object
Accessors
11 12 13 |
# File 'lib/taupe/cache/redis.rb', line 11 def connection @connection end |
Instance Method Details
#delete(key) ⇒ Object
Delete a key
36 37 38 |
# File 'lib/taupe/cache/redis.rb', line 36 def delete(key) @connection.del key end |
#get(key) ⇒ Object
Get a cache entry
22 23 24 |
# File 'lib/taupe/cache/redis.rb', line 22 def get(key) @connection.hgetall(key).symbolize_keys end |
#set(key, value) ⇒ Object
Set a cache entry
29 30 31 32 |
# File 'lib/taupe/cache/redis.rb', line 29 def set(key, value) fail 'Only HASH values are supported' unless value.is_a?(Hash) @connection.mapped_hmset key, value end |