Class: Phronomy::StateStore::Redis
- Defined in:
- lib/phronomy/state_store/redis.rb
Overview
Redis-backed state store.
Persists graph state as a JSON string under the key
"phronomy:state:
The Redis client must be compatible with the redis-rb gem interface: client.set(key, value) client.get(key) client.del(key)
Instance Method Summary collapse
- #clear(thread_id) ⇒ self
-
#initialize(client:, ttl: nil) ⇒ Redis
constructor
A new instance of Redis.
-
#load(thread_id) ⇒ Object?
State instance or nil.
- #save(state) ⇒ self
Constructor Details
#initialize(client:, ttl: nil) ⇒ Redis
Returns a new instance of Redis.
31 32 33 34 |
# File 'lib/phronomy/state_store/redis.rb', line 31 def initialize(client:, ttl: nil) @client = client @ttl = ttl end |
Instance Method Details
#clear(thread_id) ⇒ self
58 59 60 61 |
# File 'lib/phronomy/state_store/redis.rb', line 58 def clear(thread_id) @client.del(key(thread_id)) self end |
#load(thread_id) ⇒ Object?
Returns state instance or nil.
50 51 52 53 54 55 |
# File 'lib/phronomy/state_store/redis.rb', line 50 def load(thread_id) raw = @client.get(key(thread_id)) return nil unless raw deserialize_state(raw) end |
#save(state) ⇒ self
38 39 40 41 42 43 44 45 46 |
# File 'lib/phronomy/state_store/redis.rb', line 38 def save(state) serialized = serialize_state(state) if @ttl @client.set(key(state.thread_id), serialized, ex: @ttl) else @client.set(key(state.thread_id), serialized) end self end |