Class: IdempotentRequest::RedisStorage
- Inherits:
-
Object
- Object
- IdempotentRequest::RedisStorage
- Defined in:
- lib/idempotent-request/redis_storage.rb
Instance Attribute Summary collapse
-
#expire_time ⇒ Object
readonly
Returns the value of attribute expire_time.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#initialize(redis, config = {}) ⇒ RedisStorage
constructor
A new instance of RedisStorage.
- #lock(key) ⇒ Object
- #read(key) ⇒ Object
- #unlock(key) ⇒ Object
- #write(key, payload) ⇒ Object
Constructor Details
#initialize(redis, config = {}) ⇒ RedisStorage
Returns a new instance of RedisStorage.
5 6 7 8 9 |
# File 'lib/idempotent-request/redis_storage.rb', line 5 def initialize(redis, config = {}) @redis = redis @namespace = config.fetch(:namespace, 'idempotency_keys') @expire_time = config[:expire_time] end |
Instance Attribute Details
#expire_time ⇒ Object (readonly)
Returns the value of attribute expire_time.
3 4 5 |
# File 'lib/idempotent-request/redis_storage.rb', line 3 def expire_time @expire_time end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/idempotent-request/redis_storage.rb', line 3 def namespace @namespace end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
3 4 5 |
# File 'lib/idempotent-request/redis_storage.rb', line 3 def redis @redis end |
Instance Method Details
#lock(key) ⇒ Object
11 12 13 |
# File 'lib/idempotent-request/redis_storage.rb', line 11 def lock(key) setnx_with_expiration(lock_key(key), Time.now.to_f) end |
#read(key) ⇒ Object
19 20 21 |
# File 'lib/idempotent-request/redis_storage.rb', line 19 def read(key) redis.get(namespaced_key(key)) end |
#unlock(key) ⇒ Object
15 16 17 |
# File 'lib/idempotent-request/redis_storage.rb', line 15 def unlock(key) redis.del(lock_key(key)) end |
#write(key, payload) ⇒ Object
23 24 25 |
# File 'lib/idempotent-request/redis_storage.rb', line 23 def write(key, payload) setnx_with_expiration(namespaced_key(key), payload) end |