class Restruct::Locker

Constants

REGISTER_LUA
UNREGISTER_LUA

Public Instance Methods

key() click to toggle source
# File lib/restruct/locker.rb, line 19
def key
  connection.call('HGET', id, 'key')
end
Also aliased as: locked_by
lock(key, &block) click to toggle source
# File lib/restruct/locker.rb, line 7
def lock(key, &block)
  _lock key, false, &block
end
lock!(key, &block) click to toggle source
# File lib/restruct/locker.rb, line 11
def lock!(key, &block)
  _lock key, true, &block
end
locked_by()
Alias for: key
to_h() click to toggle source
# File lib/restruct/locker.rb, line 24
def to_h
  ::Hash[connection.call('HGETALL', id).each_slice(2).to_a]
end
Also aliased as: to_primitive
to_primitive()
Alias for: to_h

Private Instance Methods

_lock(key, exclusive) { || ... } click to toggle source
# File lib/restruct/locker.rb, line 31
def _lock(key, exclusive)
  connection.script REGISTER_LUA, 0, id, key, exclusive
  begin
    yield
  ensure  
    connection.script UNREGISTER_LUA, 0, id
  end      
rescue Restruct::ConnectionError => ex
  raise LockerError.new ex
end