Class: Redisse::RedisPublisher Private
- Inherits:
-
Object
- Object
- Redisse::RedisPublisher
- Includes:
- ServerSentEvents
- Defined in:
- lib/redisse/publisher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Publisher that pushes to Redis with history.
Constant Summary
- REDISSE_LAST_EVENT_ID =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
'redisse:lastEventId'.freeze
- HISTORY_SIZE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
100
Instance Method Summary (collapse)
-
- (RedisPublisher) initialize(redis)
constructor
private
A new instance of RedisPublisher.
- - (Object) publish(channel, data, type) private
Methods included from ServerSentEvents
Constructor Details
- (RedisPublisher) initialize(redis)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RedisPublisher
12 13 14 |
# File 'lib/redisse/publisher.rb', line 12 def initialize(redis) @redis = redis or raise 'RedisPublisher needs a Redis client' end |
Instance Method Details
- (Object) publish(channel, data, type)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 19 20 21 22 23 |
# 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 |