module RedisModel::Types::Counter

Internal: Methods needed for counter data type.

Public Instance Methods

incr(by = nil) click to toggle source

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.

# 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() click to toggle source

Public: Retrieves Integer value of counter.

Returns Integer value of counter.

# File lib/redis_model/types/counter.rb, line 20
def to_i
  (get || 0).to_i
end