lib/redis_exp_lock.rb
# Attempt to acquire the lock, returning true if the lock was succesfully
# acquired, and false if not.
Attempt to acquire the lock, returning true if the lock was succesfully
acquired, and false if not.
Attempt to acquire the lock returning true if the lock was succesfully acquired and false if not .
def try_lock
    raise AlreadyAcquiredLockError if locked?
    uuid = SecureRandom.uuid
    set_opts = {:nx => true}
    set_opts[:px] = Integer(@expiry * 1000) if @expiry
    if @redis.set(@lock_key, uuid, set_opts)
      @lock_uuid = uuid
      true
    else
      false
    end
  end
def try_lock raise AlreadyAcquiredLockError if locked? uuid = SecureRandom . uuid set_opts = { :nx => true } set_opts [ :px ] = Integer ( @expiry * 1000 ) if @expiry if @redis . set ( @lock_key , uuid , set_opts ) @lock_uuid = uuid true else false end end
Attempt to acquire the lock, returning true if the lock was succesfully
acquired, and false if not.
Attempt to acquire the lock returning true if the lock was succesfully acquired and false if not .