Class: Reacter::DeciderAgent::RedisPersist
- Inherits:
-
Object
- Object
- Reacter::DeciderAgent::RedisPersist
- Defined in:
- lib/reacter/agents/decider.rb
Overview
redis persistence mechanism for shared state tracking
Class Method Summary collapse
- .get(source, metric, key) ⇒ Object
- .init(source, metric) ⇒ Object
- .set(source, metric, key, value) ⇒ Object
- .setup(config = {}) ⇒ Object
Class Method Details
.get(source, metric, key) ⇒ Object
58 59 60 |
# File 'lib/reacter/agents/decider.rb', line 58 def get(source, metric, key) MessagePack.unpack(@_redis.get("#{source}:#{metric}:#{key}")) end |
.init(source, metric) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/reacter/agents/decider.rb', line 50 def init(source, metric) DEFAULT_PERSISTENCE_OBJECT.each do |key, value| @_redis.multi do @_redis.set("#{source}:#{metric}:#{key}", value.to_msgpack) end end end |
.set(source, metric, key, value) ⇒ Object
62 63 64 65 66 |
# File 'lib/reacter/agents/decider.rb', line 62 def set(source, metric, key, value) k = "#{source}:#{metric}:#{key}" @_redis.set(k, value.to_msgpack) @_redis.expire(k, @_ttl) end |
.setup(config = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/reacter/agents/decider.rb', line 39 def setup(config={}) @_redis = Redis.new({ :host => config.get(:host), :port => config.get(:port), :path => config.get(:socket), :driver => config.get(:driver, :hiredis).to_sym }) @_ttl = config.get('ttl', 600) end |