class Rdsck::Watch
Public Class Methods
new(rdsck, node, filters, set_notify_config = nil)
click to toggle source
# File lib/nchan_tools/rdsck.rb, line 111 def initialize(rdsck, node, filters, set_notify_config = nil) @rdsck = rdsck @sync = node @filters = filters @set_notify_config = set_notify_config @host, @port, @location = @sync.connection[:host], @sync.connection[:port] @url = @sync.connection[:id] @async = Async::Redis::Client.new(Async::IO::Endpoint.tcp(@host, @port)) if set_notify_config @rdsck.dbg "set #{@url} notify-keyspace-events to \"Kh\"" @prev_notify_keyspace_event_config = @sync.config("get", "notify-keyspace-events") @prev_notify_keyspace_event_config = @prev_notify_keyspace_event_config[1] if @prev_notify_keyspace_event_config @sync.config :set, "notify-keyspace-events", "Kh" end end
Public Instance Methods
stop()
click to toggle source
# File lib/nchan_tools/rdsck.rb, line 162 def stop @async.close if @set_notify_config @rdsck.dbg "set #{@url} notify-keyspace-events back to #{@prev_notify_keyspace_event_config}" @sync.config(:set, "notify-keyspace-events", @prev_notify_keyspace_event_config) end end
watch(task)
click to toggle source
# File lib/nchan_tools/rdsck.rb, line 128 def watch(task) task.async do #puts "subscribeme" while true do @async.psubscribe "__keyspace*__:{channel:*}" do |ctx| type, pattern, name, msg = ctx.listen #puts "TYPE: #{type}, PAT:#{pattern}, NAME:#{name}, MSG:#{msg}" m=name.match(/^__.*__:(\{.*\})/) if m && m[1] key = m[1] filtered = false subs = nil if @filters[:min_subscribers] subs = @sync.hget key, "fake_subscribers" subs = subs.to_i filtered = true if subs < @filters[:min_subscribers] end if !filtered if subs puts "#{key} subscribers: #{subs}" else puts "#{key}" end end end end end end end