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

#event(ev) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/camayoc/handlers/redis.rb', line 14

def event(ev)
  case ev.type
    when :count  then count(ev)
    when :timing then timing(ev)
    # generic not implemented!
  end
end

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/camayoc/handlers/redis.rb', line 22

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