Class: Domotics::Core::DataRedis
- Defined in:
- lib/domotics/core/data/data_redis.rb
Instance Method Summary collapse
- #[](obj) ⇒ Object
- #connect(args = {}) ⇒ Object
- #get(*args) ⇒ Object
-
#initialize(args = {}) ⇒ DataRedis
constructor
A new instance of DataRedis.
- #set(*args) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ DataRedis
Returns a new instance of DataRedis.
3 4 5 6 7 8 9 10 |
# 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 |
Instance Method Details
#[](obj) ⇒ Object
12 13 14 15 16 17 |
# 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 = {}) ⇒ Object
19 20 21 22 23 |
# 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) ⇒ Object
25 26 27 |
# File 'lib/domotics/core/data/data_redis.rb', line 25 def get(*args) @redis.get *args end |
#set(*args) ⇒ Object
28 29 30 |
# File 'lib/domotics/core/data/data_redis.rb', line 28 def set(*args) @redis.set *args end |