Pub/Sub

The pubsub command bridges Redis Pub/Sub messages from a source Redis database to a target Redis database. It subscribes to channels or channel patterns on the source and republishes each received message to the target.

riotx pubsub redis://source:6379 redis://target:6379 --channel orders

Redis Pub/Sub provides at-most-once delivery. Messages are not persisted and cannot be replayed if the bridge is disconnected, slow, or not yet subscribed. Use Redis Streams instead when a migration requires durable replay or stronger delivery guarantees.

Channels

Subscribe to explicit channels with --channel:

riotx pubsub redis://source:6379 redis://target:6379 \
  --channel orders --channel invoices

Subscribe to glob-style channel patterns with --channel-pattern:

riotx pubsub redis://source:6379 redis://target:6379 \
  --channel-pattern 'orders.*'

For a broad live bridge, use a pattern subscription:

riotx pubsub redis://source:6379 redis://target:6379 \
  --channel-pattern '*'

Channel Discovery

The --discover-channels option subscribes to channels returned by PUBSUB CHANNELS:

riotx pubsub redis://source:6379 redis://target:6379 \
  --discover-channels --channel-pattern 'orders.*'

Discovery only sees active channels that currently have direct subscribers. It does not discover dormant channels, channels with publishers but no subscribers, or pattern-only subscriptions. Use --discover-interval to poll for newly active channels:

riotx pubsub redis://source:6379 redis://target:6379 \
  --discover-channels --discover-interval 30s

Channel Transforms

Use --channel-proc to transform target channel names with a JavaScript expression. The original message payload is not changed.

Available variables:

  • channel: source channel name as a UTF-8 string

  • message: message payload as a UTF-8 string

  • pattern: matched pattern as a UTF-8 string, or null

  • size: payload size in bytes

riotx pubsub redis://source:6379 redis://target:6379 \
  --channel-pattern 'orders.*' \
  --channel-proc "'mirror:' + channel"

Other examples:

  • channel.replace(/^source\./, 'target.')

  • pattern != null ? 'pattern:' + channel : channel

  • 'tenant-a:' + channel

Completion

By default, Pub/Sub replication runs until interrupted. Use --idle-timeout to stop after a quiet period or --message-limit to stop after a fixed number of forwarded messages:

riotx pubsub redis://source:6379 redis://target:6379 \
  --channel orders --idle-timeout 5m

Use --dry-run to log messages that would be forwarded without publishing to the target.