Class: Redis::Promise::Resolver
- Inherits:
-
Object
- Object
- Redis::Promise::Resolver
- Defined in:
- lib/redis/promise/resolver.rb
Overview
An object used to resolve or reject a redis promise.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
: String.
-
#redis ⇒ Object
readonly
: Redis.
Instance Method Summary collapse
-
#initialize(redis, id: SecureRandom.uuid_v4, namespace: 'global', key: "promise:#{namespace}:#{id}") ⇒ Resolver
constructor
: (Redis, ?id: String, ?namespace: String, ?key: String) -> void.
-
#reject(err, expire: nil) ⇒ Object
Reject the promise with the given value.
-
#resolve(value, expire: nil) ⇒ Object
Resolve the promise with the given value.
Constructor Details
#initialize(redis, id: SecureRandom.uuid_v4, namespace: 'global', key: "promise:#{namespace}:#{id}") ⇒ Resolver
: (Redis, ?id: String, ?namespace: String, ?key: String) -> void
16 17 18 19 |
# File 'lib/redis/promise/resolver.rb', line 16 def initialize(redis, id: SecureRandom.uuid_v4, namespace: 'global', key: "promise:#{namespace}:#{id}") @redis = redis.dup #: Redis @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
: String
13 14 15 |
# File 'lib/redis/promise/resolver.rb', line 13 def key @key end |
#redis ⇒ Object (readonly)
: Redis
10 11 12 |
# File 'lib/redis/promise/resolver.rb', line 10 def redis @redis end |
Instance Method Details
#reject(err, expire: nil) ⇒ Object
Reject the promise with the given value. The value gets serialized to JSON using ‘to_json`.
There is an optional argument ‘expire:` that determines the amount of seconds after which the key-value will get automatically deleted from redis.
: (top, ?expire: Integer?) -> void
40 41 42 43 |
# File 'lib/redis/promise/resolver.rb', line 40 def reject(err, expire: nil) serialized = { err: err }.to_json push(serialized, expire) end |
#resolve(value, expire: nil) ⇒ Object
Resolve the promise with the given value. The value gets serialized to JSON using ‘to_json`.
There is an optional argument ‘expire:` that determines the amount of seconds after which the key-value will get automatically deleted from redis.
: (top, ?expire: Integer?) -> void
28 29 30 31 |
# File 'lib/redis/promise/resolver.rb', line 28 def resolve(value, expire: nil) serialized = { value: value }.to_json push(serialized, expire) end |