class Domotics::Core::DataRedis

Public Class Methods

new(args = {}) click to toggle source
# File lib/domotics/core/data/data_redis.rb, line 3
def initialize(args = {})
  @logger = args[:logger] || Logger.new(STDERR)
  @args = Hash.new
  @args[:host] = args[:host] || "127.0.0.1"
  @args[:port] = args[:port] || 6379
  @args[:driver] = :hiredis
  connect
end

Public Instance Methods

[](obj) click to toggle source
# File lib/domotics/core/data/data_redis.rb, line 12
def [](obj)
  case obj
  when Element
    DataRedisOperator.new self, "#{obj.room.name}:#{obj.name}"
  end
end
connect(args = {}) click to toggle source
# File lib/domotics/core/data/data_redis.rb, line 19
def connect(args = {})
  @logger.debug "Broken connection to redis host [#{@args[:host]}:#{@args[:port]}] detected. Reconnect." if args[:broken]
  @redis.quit if @redis
  @redis = Redis.new @args
end
get(*args) click to toggle source
# File lib/domotics/core/data/data_redis.rb, line 25
def get(*args)
  @redis.get *args
end
set(*args) click to toggle source
# File lib/domotics/core/data/data_redis.rb, line 28
def set(*args)
  @redis.set *args
end