Module: Wampus::Backends::Redis
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/wampus/backends/redis.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#redis_config ⇒ Object
readonly
Returns the value of attribute redis_config.
Instance Method Summary collapse
- #connect_to_redis ⇒ Object
- #dispatch_event(topic_uri, payload, excluded, included) ⇒ Object
- #initialize(*args) ⇒ Object
Instance Attribute Details
#redis_config ⇒ Object (readonly)
Returns the value of attribute redis_config.
9 10 11 |
# File 'lib/wampus/backends/redis.rb', line 9 def redis_config @redis_config end |
Instance Method Details
#connect_to_redis ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wampus/backends/redis.rb', line 39 def connect_to_redis @events_namespace = redis_config[:namespace] + ':events' @completed_events = [] @redis = ::Redis.new(:host => redis_config[:host], :port => redis_config[:port]) @subscriber = ::Redis.new(:host => redis_config[:host], :port => redis_config[:port]) if redis_config[:password] @redis.auth(redis_config[:password]) @subscriber.auth(redis_config[:password]) end @redis.select(redis_config[:database]) @subscriber.select(redis_config[:database]) Thread.new do @subscriber.subscribe(@events_namespace) do |on| on. do |channel, | () end end end end |
#dispatch_event(topic_uri, payload, excluded, included) ⇒ Object
65 66 67 |
# File 'lib/wampus/backends/redis.rb', line 65 def dispatch_event(topic_uri, payload, excluded, included) @redis.publish @events_namespace, [SecureRandom.uuid, topic_uri, payload, excluded, included].to_json end |
#initialize(*args) ⇒ Object
15 16 17 18 |
# File 'lib/wampus/backends/redis.rb', line 15 def initialize(*args) @redis_config = redis_defaults.dup super(*args) if defined? super end |