Class: Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/redis-lock.rb,
lib/redis-lock/version.rb

Defined Under Namespace

Classes: Lock

Instance Method Summary collapse

Instance Method Details

#lock(key, options = {}, &block) ⇒ Object

Parameters:

  • key

    is a unique string identifying the object to lock, e.g. “user-1”

  • options (:life) (defaults to: {})

    should be set, but defaults to 1 minute

  • options (:owner) (defaults to: {})

    may be set, but defaults to HOSTNAME:PID

  • options (:sleep) (defaults to: {})

    is used when trying to acquire the lock; milliseconds; defaults to 125.

  • options (:acquire) (defaults to: {})

    defaults to 10 seconds and can be used to determine how long to wait for a lock.



229
230
231
232
233
234
235
# File 'lib/redis-lock.rb', line 229

def lock( key, options = {}, &block )
  acquire = options.delete(:acquire) || 10

  lock = Redis::Lock.new self, key, options

  block_given? ? lock.lock(acquire, &block) : lock
end

#unlock(key) ⇒ Object



237
238
239
# File 'lib/redis-lock.rb', line 237

def unlock( key )
  Redis::Lock.new( self, key ).unlock
end