Sha256: 82a903f1a49f5c1f25b163594136452268263fad0e4d23795b373f82bc44b4cd

Contents?: true

Size: 561 Bytes

Versions: 2

Compression:

Stored size: 561 Bytes

Contents

class Kredis::Types::Slots < Kredis::Types::Proxying
  class NotAvailable < StandardError; end

  proxying :incr, :decr, :get, :del

  attr_accessor :available

  def reserve
    if block_given?
      begin
        if reserve
          yield
          true
        else
          false
        end
      ensure
        release
      end
    else
      if incr <= available
        true
      else
        release
        false
      end
    end
  end

  def release
    decr
  end

  def available?
    get.to_i < available
  end

  def reset
    del
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kredis-0.2.1 lib/kredis/types/slots.rb
kredis-0.2.0 lib/kredis/types/slots.rb