1

I am having channels which are coming dynamically from another file .I have to subscribe to all the channels.But I am not able to loop through redis subscribe

config=["channel1","channel2","channel3"]
config.each do |ch|
  $redis.subscribe(ch) do |on|
    #on.message......
  end
end

But it subscribes to the first element in loop.The "config" can vary dynamically.

Praveenkumar
  • 921
  • 1
  • 9
  • 28

1 Answers1

1

For multiple channels subscription you should do it like

config=["channel1","channel2","channel3"]
  $redis.subscribe(config)
end

Reference: github source code

def subscribe(*channels, &block)
  subscription("subscribe", "unsubscribe", channels, block)
end
adamliesko
  • 1,887
  • 1
  • 14
  • 21
  • Thousnads of thanks to you @admaliesko.Even i did the same but i havent saved my config as as Array.Instead i saved them as a string. – Praveenkumar Jul 27 '15 at 06:22