Class: Twitch::Bot::Memory::Redis
- Inherits:
-
Object
- Object
- Twitch::Bot::Memory::Redis
- Defined in:
- lib/twitch/bot/memory/redis.rb
Overview
Implement persistent memory based on Redis
Instance Method Summary collapse
-
#initialize(client:) ⇒ Redis
constructor
A new instance of Redis.
- #retrieve(key) ⇒ Object
- #store(key, value) ⇒ Object
Constructor Details
#initialize(client:) ⇒ Redis
11 12 13 14 |
# File 'lib/twitch/bot/memory/redis.rb', line 11 def initialize(client:) @client = client @redis = connect_db end |
Instance Method Details
#retrieve(key) ⇒ Object
20 21 22 23 |
# File 'lib/twitch/bot/memory/redis.rb', line 20 def retrieve(key) value = redis.get(key) value.nil? ? nil : JSON.parse(value) end |
#store(key, value) ⇒ Object
16 17 18 |
# File 'lib/twitch/bot/memory/redis.rb', line 16 def store(key, value) redis.set(key, value.to_json) end |