Class: BoardLinuxfr::RedisPlugin
- Inherits:
-
Object
- Object
- BoardLinuxfr::RedisPlugin
- Defined in:
- lib/board-linuxfr/redis_plugin.rb
Instance Method Summary collapse
-
#initialize(address, port, config, status, logger) ⇒ RedisPlugin
constructor
A new instance of RedisPlugin.
- #run ⇒ Object
Constructor Details
#initialize(address, port, config, status, logger) ⇒ RedisPlugin
Returns a new instance of RedisPlugin.
10 11 12 13 14 15 16 |
# File 'lib/board-linuxfr/redis_plugin.rb', line 10 def initialize(address, port, config, status, logger) logger.info "Initializing the Redis plugin" @logger = logger @chans = status[:channels] = Hash.new { |h,k| h[k] = EM::Channel.new } @cache = status[:cache] = Cache.new @redis = Redis.new(host: ENV['REDIS_HOST'] || "localhost", port: ENV['REDIS_PORT'] || 6379) end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/board-linuxfr/redis_plugin.rb', line 18 def run EM.synchrony do @redis.psubscribe("b/*") do |on| on.psubscribe do |pattern, total| @logger.info "Psubscribe to redis: #{pattern} (#{total})" end on. do |pattern, chan, msg| _, chan, id = *chan.split('/') @logger.info "New message: [#{chan.inspect}] #{id}. #{msg}" [@chans, @cache].each do |storage| storage[chan].push [id, msg] end end on.punsubscribe do |pattern, total| @logger.info "Punsubscribe to redis: #{pattern} (#{total})" end end end end |