Class: Potlock::Client
- Inherits:
-
Object
- Object
- Potlock::Client
- Defined in:
- lib/potlock/client.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#lock_key ⇒ Object
Returns the value of attribute lock_key.
Instance Method Summary collapse
- #fetch ⇒ Object
- #get ⇒ Object
-
#initialize(key:) ⇒ Client
constructor
A new instance of Client.
- #set(&block) ⇒ Object
Constructor Details
#initialize(key:) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/potlock/client.rb', line 7 def initialize(key:) @key = key @lock_key = "#{key}_lock" end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/potlock/client.rb', line 5 def key @key end |
#lock_key ⇒ Object
Returns the value of attribute lock_key.
5 6 7 |
# File 'lib/potlock/client.rb', line 5 def lock_key @lock_key end |
Instance Method Details
#fetch ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/potlock/client.rb', line 12 def fetch lock! do return redis.get(key) if redis.exists?(key) value = yield redis.set(key, value) value end rescue Redlock::LockError => _e raise Potlock::LockError end |