class Pubsubstub::Channel
Attributes
name[R]
Public Class Methods
name_from_pubsub_key(key)
click to toggle source
# File lib/pubsubstub/channel.rb, line 4 def name_from_pubsub_key(key) key.sub(/\.pubsub$/, '') end
new(name)
click to toggle source
# File lib/pubsubstub/channel.rb, line 11 def initialize(name) @name = name.to_s end
Public Instance Methods
publish(event)
click to toggle source
# File lib/pubsubstub/channel.rb, line 15 def publish(event) redis.pipelined do |pipeline| pipeline.zadd(scrollback_key, event.id, event.to_json) pipeline.zremrangebyrank(scrollback_key, 0, -Pubsubstub.channels_scrollback_size) pipeline.expire(scrollback_key, Pubsubstub.channels_scrollback_ttl) pipeline.publish(pubsub_key, event.to_json) end end
pubsub_key()
click to toggle source
# File lib/pubsubstub/channel.rb, line 32 def pubsub_key "#{name}.pubsub" end
redis()
click to toggle source
# File lib/pubsubstub/channel.rb, line 36 def redis Pubsubstub.redis end
scrollback(since: )
click to toggle source
# 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()
click to toggle source
# File lib/pubsubstub/channel.rb, line 28 def scrollback_key "#{name}.scrollback" end