Class: Redpear::Store::Counter
- Defined in:
- lib/redpear/store/counter.rb
Constant Summary
Constants inherited from Base
Base::IS_NIL, Base::IS_ONE, Base::IS_TRUE, Base::IS_ZERO, Base::PICK_FIRST, Base::TO_INT, Base::TO_SET
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#decrement(by = 1) ⇒ Object
(also: #previous, #prev)
Decrements the value.
-
#get ⇒ Integer
The value.
-
#increment(by = 1) ⇒ Object
(also: #next)
Increments the value.
-
#set(value) ⇒ Object
Sets the value.
Methods inherited from Value
#==, #append, #nil?, #replace, #respond_to?, #value, #value=
Methods inherited from Base
#clear, #exists?, #expire, #expire_at, #expire_in, #initialize, #inspect, #purge!, temporary, #ttl, #type, #value, #watch
Constructor Details
This class inherits a constructor from Redpear::Store::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Redpear::Store::Value
Instance Method Details
#decrement(by = 1) ⇒ Object Also known as: previous, prev
Decrements the value
38 39 40 41 42 43 44 45 |
# File 'lib/redpear/store/counter.rb', line 38 def decrement(by = 1) case by when 1 conn.decr(key) else conn.decrby(key, by) end end |
#get ⇒ Integer
Returns the value.
4 5 6 7 8 9 10 11 |
# File 'lib/redpear/store/counter.rb', line 4 def get case value = super when Redis::Future value.instance_eval { @transformation = TO_INT } else value.to_i end end |
#increment(by = 1) ⇒ Object Also known as: next
Increments the value
25 26 27 28 29 30 31 32 |
# File 'lib/redpear/store/counter.rb', line 25 def increment(by = 1) case by when 1 conn.incr(key) else conn.incrby(key, by) end end |
#set(value) ⇒ Object
Sets the value
15 16 17 |
# File 'lib/redpear/store/counter.rb', line 15 def set(value) super Kernel::Integer(value) end |