Class: Y::Redis
- Inherits:
-
Object
- Object
- Y::Redis
- Defined in:
- lib/y/redis.rb,
lib/y/redis/config.rb,
lib/y/redis/version.rb,
lib/y/redis/config/option.rb,
lib/y/redis/config/validations.rb,
lib/y/redis/config/abstract_builder.rb
Overview
A Y::Redis instance can be used to persist and load a Doc
Defined Under Namespace
Classes: Config, Error, MissingConfiguration, MissingConfigurationBuilderClass
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#client ⇒ ::Redis
readonly
The current value of client.
-
#lock_manager ⇒ ::Redlock::Client
readonly
The current value of lock_manager.
Class Method Summary collapse
- .configuration ⇒ Object (also: config)
- .configure(&block) ⇒ Object
Instance Method Summary collapse
-
#initialize(client, lock_manager) ⇒ Redis
constructor
A new instance of Redis.
-
#load(id) ⇒ ::Array<Integer>?
Load document from store.
-
#save(id, update) ⇒ Boolean
Save document to store.
Constructor Details
#initialize(client, lock_manager) ⇒ Redis
Returns a new instance of Redis.
40 41 42 43 |
# File 'lib/y/redis.rb', line 40 def initialize(client, lock_manager) @client = client @lock_manager = lock_manager end |
Instance Attribute Details
#client ⇒ ::Redis (readonly)
Returns the current value of client.
33 34 35 |
# File 'lib/y/redis.rb', line 33 def client @client end |
#lock_manager ⇒ ::Redlock::Client (readonly)
Returns the current value of lock_manager.
33 34 35 |
# File 'lib/y/redis.rb', line 33 def lock_manager @lock_manager end |
Class Method Details
.configuration ⇒ Object Also known as: config
24 25 26 |
# File 'lib/y/redis/config.rb', line 24 def configuration @config || (raise MissingConfiguration) end |
Instance Method Details
#load(id) ⇒ ::Array<Integer>?
Load document from store
67 68 69 70 |
# File 'lib/y/redis.rb', line 67 def load(id) data = client.get(id) decode(data) end |
#save(id, update) ⇒ Boolean
Save document to store.
This method expects a binary encoded update in the form of an Array of Integers.
53 54 55 56 57 58 59 60 61 |
# File 'lib/y/redis.rb', line 53 def save(id, update) lock_manager.lock!("resource_key", 2000) do data = encode(update) client.set(id, data) true end rescue Redlock::LockError false end |