Class: Von::Counters::Total
- Inherits:
-
Object
- Object
- Von::Counters::Total
- Includes:
- Commands
- Defined in:
- lib/von/counters/total.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Class Method Summary collapse
-
.count(field) ⇒ Object
Lookup the count for this Counter in Redis.
Instance Method Summary collapse
-
#count ⇒ Object
Count the “total” field for this Counter.
-
#hash_key ⇒ Object
Returns the Redis hash key used for storing counts for this Counter.
-
#increment ⇒ Object
Increment the total count for this Counter If the key has time periods specified, increment those.
-
#initialize(field) ⇒ Total
constructor
Initialize a new Counter.
Methods included from Commands
#hdel, #hget, #hgetall, #hincrby, #hset, #llen, #lpop, #lrange, #rpush
Constructor Details
#initialize(field) ⇒ Total
Initialize a new Counter
field - counter field name
10 11 12 |
# File 'lib/von/counters/total.rb', line 10 def initialize(field) @field = field.to_sym end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
5 6 7 |
# File 'lib/von/counters/total.rb', line 5 def field @field end |
Class Method Details
.count(field) ⇒ Object
Lookup the count for this Counter in Redis. If a Period argument is given we lookup the count for all of the possible units (not expired), zeroing ones that aren’t set in Redis already.
period - A Period to lookup
Returns an Integer representing the count or an Array of counts.
43 44 45 |
# File 'lib/von/counters/total.rb', line 43 def self.count(field) Counter.new(field).count end |
Instance Method Details
#count ⇒ Object
Count the “total” field for this Counter.
Returns an Integer count
30 31 32 33 |
# File 'lib/von/counters/total.rb', line 30 def count count = hget(hash_key, 'total') count.nil? ? 0 : count.to_i end |
#hash_key ⇒ Object
Returns the Redis hash key used for storing counts for this Counter
15 16 17 |
# File 'lib/von/counters/total.rb', line 15 def hash_key "#{Von.config.namespace}:counters:#{@field}" end |
#increment ⇒ Object
Increment the total count for this Counter If the key has time periods specified, increment those.
Returns the Integer total for the key
23 24 25 |
# File 'lib/von/counters/total.rb', line 23 def increment hincrby(hash_key, 'total', 1).to_i end |