Class: RServiceBus::SubscriptionStorage_Redis
- Inherits:
-
SubscriptionStorage
- Object
- SubscriptionStorage
- RServiceBus::SubscriptionStorage_Redis
- Defined in:
- lib/rservicebus/SubscriptionStorage/Redis.rb
Overview
Implementation of Subscription Storage to Redis
Instance Method Summary collapse
- #add(eventName, queueName) ⇒ Object
- #getAll ⇒ Object
-
#initialize(appName, uri) ⇒ SubscriptionStorage_Redis
constructor
Constructor.
- #remove(eventName, queueName) ⇒ Object
Constructor Details
#initialize(appName, uri) ⇒ SubscriptionStorage_Redis
Constructor
14 15 16 17 18 |
# File 'lib/rservicebus/SubscriptionStorage/Redis.rb', line 14 def initialize( appName, uri ) super(appName, uri) port = uri.port.nil? ? 6379 : uri.port @redis = Redis.new( :host=>uri.host, :port=>port ) end |
Instance Method Details
#add(eventName, queueName) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rservicebus/SubscriptionStorage/Redis.rb', line 43 def add( eventName, queueName ) content = @redis.get( @appName + '.Subscriptions') if content.nil? then subscriptions = Hash.new else subscriptions = YAML::load(content) end if subscriptions[eventName].nil? then subscriptions[eventName] = Array.new end subscriptions[eventName] << queueName subscriptions[eventName] = subscriptions[eventName].uniq @redis.set( @appName + '.Subscriptions', YAML::dump(subscriptions ) ) return subscriptions end |
#getAll ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rservicebus/SubscriptionStorage/Redis.rb', line 20 def getAll RServiceBus.log 'Load subscriptions' begin content = @redis.get( @appName + '.Subscriptions') if content.nil? then subscriptions = Hash.new else subscriptions = YAML::load(content) end return subscriptions rescue Exception => e puts 'Error connecting to redis' if e. == 'Redis::CannotConnectError' || e. == 'Redis::ECONNREFUSED' then puts '***Most likely, redis is not running. Start redis, and try running this again.' else puts e. puts e.backtrace end abort() end end |
#remove(eventName, queueName) ⇒ Object
63 64 65 |
# File 'lib/rservicebus/SubscriptionStorage/Redis.rb', line 63 def remove( eventName, queueName ) raise 'Method, remove, needs to be implemented for this subscription storage' end |