Class: Resque::Metrics::Backends::Redis
- Inherits:
-
Object
- Object
- Resque::Metrics::Backends::Redis
- Defined in:
- lib/resque/metrics/backends/redis.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #get_metric(metric) ⇒ Object
- #increment_metric(metric, by = 1) ⇒ Object
-
#initialize(redis) ⇒ Redis
constructor
A new instance of Redis.
- #known_jobs ⇒ Object
- #register_job(job) ⇒ Object
- #set_avg(metric, num, total) ⇒ Object
- #set_metric(metric, val) ⇒ Object
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
#redis ⇒ Object
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_jobs ⇒ Object
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 |