Class: Kredis::Types::Counter

Inherits:
Proxying
  • Object
show all
Includes:
DefaultValues
Defined in:
lib/kredis/types/counter.rb

Direct Known Subclasses

Cycle, Limiter

Instance Attribute Summary collapse

Attributes inherited from Proxying

#key, #proxy

Instance Method Summary collapse

Methods included from DefaultValues

#initialize

Methods inherited from Proxying

#failsafe, #initialize, proxying, #unproxied_redis

Instance Attribute Details

#expires_inObject

Returns the value of attribute expires_in.



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

def expires_in
  @expires_in
end

Instance Method Details

#decrement(by: 1) ⇒ Object



17
18
19
20
21
22
# File 'lib/kredis/types/counter.rb', line 17

def decrement(by: 1)
  multi do
    set 0, ex: expires_in, nx: true if expires_in
    decrby by
  end[-1]
end

#increment(by: 1) ⇒ Object



10
11
12
13
14
15
# File 'lib/kredis/types/counter.rb', line 10

def increment(by: 1)
  multi do
    set 0, ex: expires_in, nx: true if expires_in
    incrby by
  end[-1]
end

#resetObject



28
29
30
# File 'lib/kredis/types/counter.rb', line 28

def reset
  del
end

#valueObject



24
25
26
# File 'lib/kredis/types/counter.rb', line 24

def value
  get.to_i
end