Module: Tor::Lock

Included in:
Tor
Defined in:
lib/rest_tor/lock.rb

Instance Method Summary collapse

Instance Method Details

#lock(key, expires: 10*60, timeout: 1 * 60 * 0, &block) ⇒ Object



3
4
5
# File 'lib/rest_tor/lock.rb', line 3

def lock(key, expires: 10*60, timeout: 1 * 60 * 0, &block)
  Redis::Lock.new("tor:lock:#{key}", expiration: expires, timeout: timeout).lock { yield }
end

#locked?(key) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rest_tor/lock.rb', line 7

def locked?(key)
  Redis.current.get("tor:lock:#{key}")
end

#unlock!(key) ⇒ Object



11
12
13
# File 'lib/rest_tor/lock.rb', line 11

def unlock!(key)
  Redis.current.del("tor:lock:#{key}")
end