Class: AboutYou::SDK::CacheProvider::Redis
- Inherits:
-
Object
- Object
- AboutYou::SDK::CacheProvider::Redis
- Defined in:
- lib/AboutYou/CacheProvider/redis.rb
Overview
This class is used as an interface for cache operations. It is used when caching with Redis.
- author
-
Collins GmbH & Co KG
Instance Attribute Summary collapse
-
#client ⇒ Object
an instance of the cache client.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
This method is used for deleting cache entries with Redis.
-
#exists(key) ⇒ Object
This method is used for checking whether a cache entry exists or not with Redis.
-
#get(key) ⇒ Object
This method is used for getting cache entries with Redis.
-
#initialize(client) ⇒ Redis
constructor
the Constructor for the Redis class.
-
#set(key, value, duration) ⇒ Object
This method is used for setting new cache entries with Redis.
Constructor Details
#initialize(client) ⇒ Redis
the Constructor for the Redis class
-
Args :
-
client
-> an instance of Redis
-
-
Returns :
-
Instance of AboutYou::SDK::CacheProvider::Redis
-
25 26 27 |
# File 'lib/AboutYou/CacheProvider/redis.rb', line 25 def initialize(client) self.client = client end |
Instance Attribute Details
#client ⇒ Object
an instance of the cache client.
14 15 16 |
# File 'lib/AboutYou/CacheProvider/redis.rb', line 14 def client @client end |
Instance Method Details
#delete(key) ⇒ Object
This method is used for deleting cache entries with Redis.
-
Args :
-
key
-> The key of the cache entry
-
-
Returns :
-
True/False determining whether the deletion was successful or not
-
68 69 70 |
# File 'lib/AboutYou/CacheProvider/redis.rb', line 68 def delete(key) client.del(key) end |
#exists(key) ⇒ Object
This method is used for checking whether a cache entry exists or not with Redis.
-
Args :
-
key
-> The key of the cache entry
-
-
Returns :
-
True/False determining whether the key exists in the cache or not
-
81 82 83 |
# File 'lib/AboutYou/CacheProvider/redis.rb', line 81 def exists(key) client.exists(key) end |
#get(key) ⇒ Object
This method is used for getting cache entries with Redis.
-
Args :
-
key
-> The key of the cache entry
-
-
Returns :
-
Either the value for the given key or nil if the key was not found
-
55 56 57 |
# File 'lib/AboutYou/CacheProvider/redis.rb', line 55 def get(key) JSON.parse(client.get(key)) end |
#set(key, value, duration) ⇒ Object
This method is used for setting new cache entries with Redis.
-
Args :
-
key
-> The key of the cache entry -
value
-> The value of the cache entry -
duration
-> the duration of the cache entry
-
-
Returns :
-
True/False determining whether the setting was successful of not
-
40 41 42 43 44 |
# File 'lib/AboutYou/CacheProvider/redis.rb', line 40 def set(key, value, duration) value = value.to_json unless value.is_a?(String) client.set(key, value) client.expire(key, duration) end |