Class: Resque::Metrics::Backends::Redis

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/metrics/backends/redis.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ Redis

Returns a new instance of Redis.



7
8
9
# File 'lib/resque/metrics/backends/redis.rb', line 7

def initialize(redis)
  @redis = redis
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



5
6
7
# File 'lib/resque/metrics/backends/redis.rb', line 5

def redis
  @redis
end

Instance Method Details

#get_metric(metric) ⇒ Object



24
25
26
# File 'lib/resque/metrics/backends/redis.rb', line 24

def get_metric(metric)
  redis.get("_metrics_:#{metric}").to_i
end

#increment_metric(metric, by = 1) ⇒ Object



11
12
13
# File 'lib/resque/metrics/backends/redis.rb', line 11

def increment_metric(metric, by = 1)
  redis.incrby("_metrics_:#{metric}", by)
end

#known_jobsObject



32
33
34
# File 'lib/resque/metrics/backends/redis.rb', line 32

def known_jobs
  redis.smembers('_metrics_:known_jobs')
end

#register_job(job) ⇒ Object



28
29
30
# File 'lib/resque/metrics/backends/redis.rb', line 28

def register_job(job)
  redis.sadd('_metrics_:known_jobs', job)
end

#set_avg(metric, num, total) ⇒ Object



19
20
21
22
# File 'lib/resque/metrics/backends/redis.rb', line 19

def set_avg(metric, num, total)
  val = total < 1 ? 0 : num / total
  set_metric(metric, val)
end

#set_metric(metric, val) ⇒ Object



15
16
17
# File 'lib/resque/metrics/backends/redis.rb', line 15

def set_metric(metric, val)
  redis.set("_metrics_:#{metric}", val)
end