Class: Novel::RepositoryAdapters::Redis
- Inherits:
-
Object
- Object
- Novel::RepositoryAdapters::Redis
- Defined in:
- lib/novel/repository_adapters/redis.rb
Instance Attribute Summary collapse
-
#connection_pool ⇒ Object
readonly
Returns the value of attribute connection_pool.
Instance Method Summary collapse
- #find_context(saga_id) ⇒ Object
-
#initialize(connection_pool:) ⇒ Redis
constructor
A new instance of Redis.
- #persist_context(saga_id, context) ⇒ Object
Constructor Details
#initialize(connection_pool:) ⇒ Redis
Returns a new instance of Redis.
6 7 8 |
# File 'lib/novel/repository_adapters/redis.rb', line 6 def initialize(connection_pool:) @connection_pool = connection_pool end |
Instance Attribute Details
#connection_pool ⇒ Object (readonly)
Returns the value of attribute connection_pool.
4 5 6 |
# File 'lib/novel/repository_adapters/redis.rb', line 4 def connection_pool @connection_pool end |
Instance Method Details
#find_context(saga_id) ⇒ Object
10 11 12 13 |
# File 'lib/novel/repository_adapters/redis.rb', line 10 def find_context(saga_id) result = connection_pool.with { |r| r.get("novel.sagas.#{saga_id}") } result ? Marshal.load(result) : nil end |
#persist_context(saga_id, context) ⇒ Object
15 16 17 18 |
# File 'lib/novel/repository_adapters/redis.rb', line 15 def persist_context(saga_id, context) connection_pool.with { |r| r.set("novel.sagas.#{saga_id}", Marshal.dump(context)) } context end |