Class: Kredis::Types::Slots

Inherits:
Proxying show all
Defined in:
lib/kredis/types/slots.rb

Defined Under Namespace

Classes: NotAvailable

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy

Instance Method Summary collapse

Methods inherited from Proxying

#failsafe, #initialize, proxying, #unproxied_redis

Constructor Details

This class inherits a constructor from Kredis::Types::Proxying

Instance Attribute Details

#availableObject

Returns the value of attribute available.



8
9
10
# File 'lib/kredis/types/slots.rb', line 8

def available
  @available
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/kredis/types/slots.rb', line 43

def available?
  failsafe returning: false do
    taken < available
  end
end

#releaseObject



34
35
36
37
38
39
40
41
# File 'lib/kredis/types/slots.rb', line 34

def release
  if taken > 0
    decr
    true
  else
    false
  end
end

#reserveObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kredis/types/slots.rb', line 10

def reserve
  failsafe returning: false do
    if block_given?
      begin
        if reserve
          yield
          true
        else
          false
        end
      ensure
        release
      end
    else
      if available?
        incr
        true
      else
        false
      end
    end
  end
end

#resetObject



49
50
51
# File 'lib/kredis/types/slots.rb', line 49

def reset
  del
end

#takenObject



53
54
55
# File 'lib/kredis/types/slots.rb', line 53

def taken
  get.to_i
end