Class: Retriever::Storage::Redis
- Inherits:
-
Object
- Object
- Retriever::Storage::Redis
- Defined in:
- lib/retriever/storage/redis.rb
Overview
Storage handler for a Redis Backend
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Instance of Redis.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
Delete record from storage.
-
#get(key) ⇒ Object
Get record from storage.
-
#initialize ⇒ Redis
constructor
Instantiate Redis Connection (Default Settings Used).
-
#set(key, value) ⇒ Object
Set record in storage.
Constructor Details
#initialize ⇒ Redis
Instantiate Redis Connection (Default Settings Used)
12 13 14 |
# File 'lib/retriever/storage/redis.rb', line 12 def initialize @storage = ::Redis.new end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Instance of Redis
8 9 10 |
# File 'lib/retriever/storage/redis.rb', line 8 def storage @storage end |
Instance Method Details
#delete(key) ⇒ Object
Delete record from storage.
35 36 37 |
# File 'lib/retriever/storage/redis.rb', line 35 def delete(key) storage.del key end |
#get(key) ⇒ Object
Get record from storage. Deserialize value from JSON if applicable.
28 29 30 31 |
# File 'lib/retriever/storage/redis.rb', line 28 def get(key) value = storage.get(key) JSON.parse(value) rescue value end |
#set(key, value) ⇒ Object
Set record in storage. Serializes value to JSON if applicable.
19 20 21 22 23 |
# File 'lib/retriever/storage/redis.rb', line 19 def set(key, value) value = serialize(value) storage.set(key, value) JSON.parse(value) rescue value end |