Module: RedisModel::Types::Counter
- Includes:
- BaseValue
- Defined in:
- lib/redis_model/types/counter.rb
Overview
Internal: Methods needed for counter data type.
Instance Method Summary collapse
-
#incr(by = nil) ⇒ Object
Public: Atomically increments counter value using Redis command INCR or INCRBY.
-
#to_i ⇒ Object
Public: Retrieves Integer value of counter.
Methods included from BaseValue
Methods included from Base
Instance Method Details
#incr(by = nil) ⇒ Object
Public: Atomically increments counter value using Redis command INCR or INCRBY.
by - Amount to increment by (default: 1).
Returns Integer value of counter after increment.
13 14 15 |
# File 'lib/redis_model/types/counter.rb', line 13 def incr(by = nil) by ? connection.incrby(key_label, by) : connection.incr(key_label) end |
#to_i ⇒ Object
Public: Retrieves Integer value of counter.
Returns Integer value of counter.
20 21 22 |
# File 'lib/redis_model/types/counter.rb', line 20 def to_i (get || 0).to_i end |