Sha256: 63ca7736748259e2a548368b6a36c36a27c22202813ad6e1b8ef93fb739e2248

Contents?: true

Size: 315 Bytes

Versions: 2

Compression:

Stored size: 315 Bytes

Contents

class Kredis::Types::Mutex < Kredis::Proxy
  def initialize(redis, key, expires_in: nil)
    @expires_in = expires_in
    super redis, key
  end

  def lock
    set 1, ex: @expires_in
  end

  def unlock
    del
  end

  def locked?
    get
  end

  def synchronize
    lock
    yield
  ensure
    unlock
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kredis-0.1.1 lib/kredis/types/mutex.rb
kredis-0.1.0 lib/kredis/types/mutex.rb