Class: WideReceiver::Adapters::RedisAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/wide_receiver/adapters/redis_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, workers, config: Config.instance) ⇒ RedisAdapter

Returns a new instance of RedisAdapter.



12
13
14
15
16
17
18
19
# File 'lib/wide_receiver/adapters/redis_adapter.rb', line 12

def initialize(channel, workers, config: Config.instance)
  @pattern = channel
  @workers = workers.map { |w| Object.const_get(w) }
  @config  = config

  @input   = redis_connection
  @error   = Redis::Namespace.new(:wide_receiver, redis: redis_connection)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/wide_receiver/adapters/redis_adapter.rb', line 10

def config
  @config
end

#errorObject (readonly)

Returns the value of attribute error.



10
11
12
# File 'lib/wide_receiver/adapters/redis_adapter.rb', line 10

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input.



10
11
12
# File 'lib/wide_receiver/adapters/redis_adapter.rb', line 10

def input
  @input
end

Instance Method Details

#workObject



21
22
23
24
25
26
27
# File 'lib/wide_receiver/adapters/redis_adapter.rb', line 21

def work
  @input.psubscribe(@pattern) do |on|
    on.pmessage do |pattern, channel, message|
      send_workers channel, processed(message)
    end
  end
end