Ferricstore.Commands.PubSub (ferricstore v0.3.1)

Copy Markdown View Source

Handles Redis pub/sub commands that go through the normal dispatcher: PUBLISH, and PUBSUB (with subcommands CHANNELS, NUMSUB, NUMPAT).

The SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, and PUNSUBSCRIBE commands are handled directly in Ferricstore.Server.Connection because they require per-connection state management (pub/sub mode tracking, subscription counts).

Summary

Functions

Handles a PUBLISH or PUBSUB command.

Functions

handle(cmd, args)

@spec handle(binary(), [binary()]) :: term()

Handles a PUBLISH or PUBSUB command.

PUBLISH channel message

Publishes message to the given channel. Returns the number of subscribers that received the message (integer).

PUBSUB CHANNELS [pattern]

Lists channels with active subscribers. When pattern is given, only channels matching the glob pattern are returned.

PUBSUB NUMSUB [channel ...]

Returns a flat list of [channel, count, channel, count, ...] with subscriber counts for each specified channel.

PUBSUB NUMPAT

Returns the total number of active pattern subscriptions (from PSUBSCRIBE).

Parameters

  • cmd - Uppercased command name ("PUBLISH" or "PUBSUB")
  • args - List of string arguments

Returns

Plain Elixir terms suitable for RESP encoding.