Module: CrappyCounter
- Defined in:
- lib/crappy_counter.rb,
lib/crappy_counter/version.rb
Constant Summary collapse
- NoRedisFound =
Class.new(StandardError)
- VERSION =
"0.0.3"
Class Method Summary collapse
Class Method Details
.incr(opts) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/crappy_counter.rb', line 7 def self.incr(opts) raise NoRedisFound unless $redis combined_key = "" opts[:keys].each do |key| combined_key << (combined_key.empty? ? key : ":#{key}") $redis.incr combined_key date_key = "" if opts[:date] date = opts[:date] date_key << "#{combined_key}:" [:year, :month, :day].each do |date_param| next unless date.respond_to?(date_param) date_key << date.send(date_param).to_s $redis.incr date_key end end end end |
.lpush(opts) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/crappy_counter.rb', line 28 def self.lpush(opts) raise NoRedisFound unless $redis combined_key = "" opts[:keys].each do |key| combined_key << (combined_key.empty? ? key : ":#{key}") $redis.lpush combined_key, opts[:values] end end |