Class: Camayoc::Handlers::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/camayoc/handlers/redis.rb

Overview

This class is experimental.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Redis

Returns a new instance of Redis.



9
10
11
12
# File 'lib/camayoc/handlers/redis.rb', line 9

def initialize(options={})
  @namespace = options.delete(:namespace)
  @redis = (options[:redis] || ::Redis.new(options))
end

Instance Method Details

#count(event) ⇒ Object



14
15
16
# File 'lib/camayoc/handlers/redis.rb', line 14

def count(event)
  @redis.incrby(key(event.ns_stat),event.value)
end

#get(stat) ⇒ Object Also known as: []



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/camayoc/handlers/redis.rb', line 26

def get(stat)
  value = @redis.get(key(stat))
  if value == "timing"
    Timing.new(
      @redis.get(key("#{stat}:_total")).to_i, 
      @redis.get(key("#{stat}:_count")).to_i,
      nil,nil # Don't support min and max right now in redis
    )
  elsif value
    value.to_i
  else
    nil
  end
end

#timing(event) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/camayoc/handlers/redis.rb', line 18

def timing(event)
  stat = event.ns_stat
  ms = event.value
  @redis.set(key(stat),"timing")
  @redis.incrby(key("#{stat}:_count"),1)
  @redis.incrby(key("#{stat}:_total"),ms)
end