class Redisse::RedisPublisher

Internal: Publisher that pushes to Redis with history.

Constants

HISTORY_SIZE
REDISSE_LAST_EVENT_ID

Public Class Methods

new(redis) click to toggle source
# File lib/redisse/publisher.rb, line 12
def initialize(redis)
  @redis = redis or raise 'RedisPublisher needs a Redis client'
end

Public Instance Methods

publish(channel, data, type) click to toggle source
# File lib/redisse/publisher.rb, line 16
def publish(channel, data, type)
  event_id = @redis.incr(REDISSE_LAST_EVENT_ID)
  event = server_sent_event(data, type: type, id: event_id)
  @redis.publish(channel, event)
  @redis.zadd(channel, event_id, event)
  @redis.zremrangebyrank(channel, 0, -1-HISTORY_SIZE)
  event_id
end