Class: MessageChannel

Inherits:
RedisConnection show all
Defined in:
lib/redis_store.rb

Instance Attribute Summary collapse

Attributes inherited from RedisConnection

#redis

Instance Method Summary collapse

Methods inherited from RedisConnection

#counters

Constructor Details

#initialize(channel) ⇒ MessageChannel

Returns a new instance of MessageChannel.



111
112
113
114
# File 'lib/redis_store.rb', line 111

def initialize channel
  @channel = channel
  super
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



109
110
111
# File 'lib/redis_store.rb', line 109

def channel
  @channel
end

Instance Method Details

#publish(message) ⇒ Object



122
123
124
125
126
127
128
# File 'lib/redis_store.rb', line 122

def publish message
  redis.pipelined do
    @redis.hincrby "counters", @channel, 1
    #@redis.hincrby "ts:counters", keygen+"_count", 1      
    @redis.publish(@channel, message )
  end
end

#subscribe(&proc) ⇒ Object



116
117
118
119
120
# File 'lib/redis_store.rb', line 116

def subscribe &proc
  @redis.subscribe @channel do |on|
  on.message &proc
  end
end

#to_sObject



130
131
132
# File 'lib/redis_store.rb', line 130

def to_s
  @channel
end