Class: Autoscaler::CounterCacheRedis
- Inherits:
-
Object
- Object
- Autoscaler::CounterCacheRedis
- Defined in:
- lib/autoscaler/counter_cache_redis.rb
Overview
Implements a cache for the number of heroku works currently up This permits some web/worker communication, which makes longer timeouts practical.
Defined Under Namespace
Classes: Expired
Instance Method Summary collapse
-
#counter ⇒ Object
Current value.
- #counter=(value) ⇒ Object
-
#initialize(redis, timeout = 5 * 60, worker_type = 'worker') ⇒ CounterCacheRedis
constructor
A new instance of CounterCacheRedis.
Constructor Details
#initialize(redis, timeout = 5 * 60, worker_type = 'worker') ⇒ CounterCacheRedis
Returns a new instance of CounterCacheRedis.
11 12 13 14 15 |
# File 'lib/autoscaler/counter_cache_redis.rb', line 11 def initialize(redis, timeout = 5 * 60, worker_type = 'worker') @redis = redis @timeout = timeout @worker_type = worker_type end |
Instance Method Details
#counter ⇒ Object
Current value. Uses the Hash#fetch api - pass a block to use in place of expired values or it will raise an exception.
26 27 28 29 30 31 |
# File 'lib/autoscaler/counter_cache_redis.rb', line 26 def counter value = redis {|c| c.get(key)} return value.to_i if value return yield if block_given? raise Expired end |
#counter=(value) ⇒ Object
18 19 20 |
# File 'lib/autoscaler/counter_cache_redis.rb', line 18 def counter=(value) redis {|c| c.setex(key, @timeout, value)} end |