Module: Protocol::Redis::Cluster::Methods::Pubsub

Defined in:
lib/protocol/redis/cluster/methods/pubsub.rb

Overview

Provides Redis Pub/Sub commands for cluster environments. Uses sharded pub/sub by default for optimal cluster performance.

Instance Method Summary collapse

Instance Method Details

#publish(channel, message, role: :master) ⇒ Object

Post a message to a channel using cluster-optimized sharded publish. Routes the message directly to the appropriate shard based on the channel name.



19
20
21
22
23
24
25
# File 'lib/protocol/redis/cluster/methods/pubsub.rb', line 19

def publish(channel, message, role: :master)
  # Route to the correct shard based on channel name:
  slot = slot_for(channel)
  client = client_for(slot, role)
  
  return client.call("SPUBLISH", channel, message)
end