Sha256: 17092bc19d77d084077907acd93ab99afb7427145d03f0009bdeb4fdc5e5b1f3

Contents?: true

Size: 683 Bytes

Versions: 5

Compression:

Stored size: 683 Bytes

Contents

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

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

  attr_accessor :available

  def reserve
    failsafe returning: false do
      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
  end

  def release
    decr
  end

  def available?
    failsafe returning: false do
      get.to_i < available
    end
  end

  def reset
    del
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kredis-0.4.0 lib/kredis/types/slots.rb
kredis-0.3.1 lib/kredis/types/slots.rb
kredis-0.3.0 lib/kredis/types/slots.rb
kredis-0.2.3 lib/kredis/types/slots.rb
kredis-0.2.2 lib/kredis/types/slots.rb