Class: Tally::Increment

Inherits:
Object
  • Object
show all
Includes:
Keyable
Defined in:
lib/tally/increment.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Keyable

#day, #initialize

Class Method Details

.increment(key, record = nil, by = 1) ⇒ Object



18
19
20
21
22
# File 'lib/tally/increment.rb', line 18

def self.increment(key, record = nil, by = 1)
  instance = new(key, record)
  instance.increment(by)
  instance = nil
end

Instance Method Details

#increment(by = 1) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/tally/increment.rb', line 6

def increment(by = 1)
  Tally.redis do |conn|
    conn.multi do |pipeline|
      pipeline.incrby(redis_key, by)
      pipeline.expire(redis_key, Tally.config.ttl.to_i) if Tally.config.ttl.present?

      pipeline.sadd(daily_key, simple_key)
      pipeline.expire(daily_key, Tally.config.ttl.to_i) if Tally.config.ttl.present?
    end
  end
end