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

Methods included from BaseValue

#get, #set

Methods included from Base

#connection, #del, #exists?

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_iObject

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