Class: Radar::Status

Inherits:
Resource show all
Defined in:
lib/radar_client_rb/resource.rb

Instance Method Summary collapse

Methods inherited from Resource

#logger

Constructor Details

#initialize(client, name) ⇒ Status

Returns a new instance of Status.


58
59
60
# File 'lib/radar_client_rb/resource.rb', line 58

def initialize(client, name)
  super(client, "status:/#{client.subdomain}/#{name}")
end

Instance Method Details

#get(key) ⇒ Object


62
63
64
65
# File 'lib/radar_client_rb/resource.rb', line 62

def get(key)
  result = @client.redis.hget(@name, key)
  result ? JSON.parse(result, :quirks_mode => true) : nil
end

#set(key, value) ⇒ Object


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/radar_client_rb/resource.rb', line 67

def set(key, value)
  redis = @client.redis
  redis.multi do |redis|
    redis.hset(@name, key, value.to_json)
    redis.expire(@name, 12*60*60)
    redis.publish(@name, { :to => @name, :op => 'set', :key => key, :value => value }.to_json)
  end

  client = redis.respond_to?(:client) && redis.client
  client_info = if client && client.respond_to?(:host) && client.respond_to?(:port)
    "Client: #{client.host}:#{client.port}"
  else
    "unknown"
  end
  logger.debug "Set Status: #{key}, #{value}, #{client_info}"
end