Sha256: 0d2feb3d74df37fcc851f278ec6a5cd6cc68f4e39b2ade53502608583f3dbc9c
Contents?: true
Size: 836 Bytes
Versions: 1
Compression:
Stored size: 836 Bytes
Contents
require "redis" require "json" module Juggernaut EVENTS = [ "juggernaut:subscribe", "juggernaut:unsubscribe", "juggernaut:custom" ] def options @options ||= {} end def options=(val) @options = val end def url=(url) options[:url] = url end def publish(channels, data, options = {}) message = ({:channels => Array(channels).uniq, :data => data}).merge(options) redis.publish(key, message.to_json) end def subscribe Redis.new(redis_options).subscribe(*EVENTS) do |on| on.message do |type, msg| yield(type.gsub(/^juggernaut:/, "").to_sym, JSON.parse(msg)) end end end protected def redis @redis ||= Redis.connect(options) end def key(*args) args.unshift(:juggernaut).join(":") end extend self end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
juggernaut-2.0.2 | lib/juggernaut.rb |