Pub/Sub Commands

SUBSCRIBE, PUBLISH, PSUBSCRIBE and real-time messaging.

SUBSCRIBE

SUBSCRIBE channel [channel ...]

Enters subscription mode. The client receives messages published to the specified channels.

UNSUBSCRIBE

UNSUBSCRIBE [channel ...]

Unsubscribe from channels. If no channels specified, unsubscribes from all.

PSUBSCRIBE

PSUBSCRIBE pattern [pattern ...]

Subscribe using glob patterns:

PSUBSCRIBE user.*        # matches user.signup, user.login, etc.
PSUBSCRIBE news.[a-z]*   # matches news.tech, news.sports

PUNSUBSCRIBE

PUNSUBSCRIBE [pattern ...]

PUBLISH

PUBLISH channel message

Returns the number of subscribers that received the message.

PUBLISH notifications "order:123 shipped"
# (integer) 3

PUBSUB

Query subscription state:

PUBSUB CHANNELS [pattern]  # list active channels
PUBSUB NUMSUB ch1 ch2      # subscriber count per channel
PUBSUB NUMPAT              # total pattern subscriptions

Message Format

Subscribers receive messages as RESP arrays:

*3
$7
message
$13
notifications
$21
order:123 shipped

Pattern subscribers receive an extra field (the matched pattern):

*4
$8
pmessage
$6
user.*
$11
user.signup
$12
{user data}

Performance

FyroDB delivers 36.8M messages/sec with 50 subscribers and pipelined publishing. The publish path holds zero locks — it reads an Arc-cloned snapshot of the subscriber list.