Module: RubyReactor::Storage::RedisPubSub
- Included in:
- RedisAdapter
- Defined in:
- lib/ruby_reactor/storage/redis_pub_sub.rb
Overview
The completion-signal channel behind the notified wait. Pure latency optimisation: at-most-once, unpersisted, never load-bearing — every waiting path ends at a durable record, so a lost signal costs a fallback interval and never correctness.
Instance Method Summary collapse
- #publish(channel, message) ⇒ Object
-
#subscribe(channel, &block) ⇒ Object
SUBSCRIBE puts a connection into subscriber mode — every other command on it then fails — so this MUST NOT use the shared client, or one waiter would poison storage for the whole process.
Instance Method Details
#publish(channel, message) ⇒ Object
26 27 28 |
# File 'lib/ruby_reactor/storage/redis_pub_sub.rb', line 26 def publish(channel, ) @redis.publish(channel, ) end |
#subscribe(channel, &block) ⇒ Object
SUBSCRIBE puts a connection into subscriber mode — every other command on it then fails — so this MUST NOT use the shared client, or one waiter would poison storage for the whole process. A dedicated connection is opened per subscription and closed on the way out.
Blocks the calling thread until the block returns truthy for a message (completion signals are one-shot) or the thread is killed.
17 18 19 20 21 22 23 24 |
# File 'lib/ruby_reactor/storage/redis_pub_sub.rb', line 17 def subscribe(channel, &block) connection = Redis.new(@redis_config) connection.subscribe(channel) do |on| on. { |_channel, | connection.unsubscribe if block.call() } end ensure connection&.close end |