class Pakyow::Realtime::Server::Adapters::Redis::Buffer
Constants
- PUBLISH_BUFFER_FLUSH_MS
How often the publish buffer should be flushed.
- PUBLISH_BUFFER_SIZE
The number of publish commands to pipeline to redis.
Public Class Methods
new(redis, channel)
click to toggle source
# File lib/pakyow/realtime/server/adapters/redis.rb, line 205 def initialize(redis, channel) @redis, @channel = redis, channel @buffer = Concurrent::Array.new end
Public Instance Methods
<<(payload)
click to toggle source
# File lib/pakyow/realtime/server/adapters/redis.rb, line 210 def <<(payload) @buffer << payload maybe_flush end
Protected Instance Methods
flush()
click to toggle source
# File lib/pakyow/realtime/server/adapters/redis.rb, line 229 def flush @redis.with do |redis| redis.pipelined do |pipeline| until @buffer.empty? pipeline.publish(@channel, @buffer.shift) end end end end
maybe_flush()
click to toggle source
# File lib/pakyow/realtime/server/adapters/redis.rb, line 217 def maybe_flush if @buffer.count > PUBLISH_BUFFER_SIZE flush end unless @task&.pending? @task = Concurrent::ScheduledTask.execute(PUBLISH_BUFFER_FLUSH_MS / 1_000) { flush } end end