Class: Pubsubstub::Channel
- Inherits:
-
Object
- Object
- Pubsubstub::Channel
- Defined in:
- lib/pubsubstub/channel.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Channel
constructor
A new instance of Channel.
- #publish(event) ⇒ Object
- #pubsub_key ⇒ Object
- #redis ⇒ Object
- #scrollback(since:) ⇒ Object
- #scrollback_key ⇒ Object
Constructor Details
#initialize(name) ⇒ Channel
Returns a new instance of Channel.
11 12 13 |
# File 'lib/pubsubstub/channel.rb', line 11 def initialize(name) @name = name.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/pubsubstub/channel.rb', line 9 def name @name end |
Class Method Details
.name_from_pubsub_key(key) ⇒ Object
4 5 6 |
# File 'lib/pubsubstub/channel.rb', line 4 def name_from_pubsub_key(key) key.sub(/\.pubsub$/, '') end |
Instance Method Details
#publish(event) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pubsubstub/channel.rb', line 15 def publish(event) redis.pipelined do redis.zadd(scrollback_key, event.id, event.to_json) redis.zremrangebyrank(scrollback_key, 0, -Pubsubstub.channels_scrollback_size) redis.expire(scrollback_key, Pubsubstub.channels_scrollback_ttl) redis.publish(pubsub_key, event.to_json) end end |
#pubsub_key ⇒ Object
32 33 34 |
# File 'lib/pubsubstub/channel.rb', line 32 def pubsub_key "#{name}.pubsub" end |
#redis ⇒ Object
36 37 38 |
# File 'lib/pubsubstub/channel.rb', line 36 def redis Pubsubstub.redis end |
#scrollback(since:) ⇒ Object
24 25 26 |
# File 'lib/pubsubstub/channel.rb', line 24 def scrollback(since: ) redis.zrangebyscore(scrollback_key, Integer(since) + 1, '+inf').map(&Event.method(:from_json)) end |
#scrollback_key ⇒ Object
28 29 30 |
# File 'lib/pubsubstub/channel.rb', line 28 def scrollback_key "#{name}.scrollback" end |