How to stream Postgres to Redis
Receive Postgres changes in Redis Streams in real-time
This guide shows you how to set up Postgres change data capture (CDC) and XADD
changes to a Redis stream using Sequin.
With Postgres data streaming to Redis, you can trigger workflows, keep services in sync, build audit logs, maintain caches, and more.
By the end of this how-to, you’ll have database changes flowing to a Redis stream.
Prerequisites
If you’re self-hosting Sequin, you’ll need:
- Sequin installed
- A database connected
- A Redis instance ready to go
If you’re using Sequin Cloud, you’ll need:
- A Sequin Cloud account
- A database connected
- A Redis instance ready to go
Create Redis sink
Navigate to the “Sinks” tab, click “Create Sink”, and select “Redis Sink”.
Configure the source
Select source table
Under “Source”, select the table you want to stream data from.
Choose message type
Specify whether you want to receive changes or rows from the table.
If you’re not sure which to choose, you can start with the default, “Changes”.
Specify filters
If you selected changes, in “Records to process”, you can indicate whether you want to receive insert
, update
, and/or delete
changes.
You can also specify SQL filters to narrow down the events you want to receive. For example, if you only want to receive events for subscriptions
that currently have an mrr
greater than $100, you can add a filter on mrr > 100
.
Specify backfill
You can optionally indicate if you want Redis to receive a backfill of all or a portion of the table’s existing data. Backfills are useful if you want to use Redis to process historical data.
You can backfill at any time. If you don’t want to backfill, toggle “Backfill” off.
Specify message grouping
Under “Message grouping”, you’ll most likely want to leave the default option selected to ensure events for the same row are sent to Redis in order.
Configure Redis
Enter Redis connection details
Fill in your Redis connection details:
- Host (required): The hostname of your Redis server
- Port (required): The port number (1-65535)
- Stream key (required): The name of the stream where messages will be published (max 255 characters)
- Username: Redis username for authentication (optional)
- Password: Redis password for authentication (optional)
- Database: Redis database number (optional, defaults to 0)
- TLS: Enable TLS/SSL encryption for the connection (optional, defaults to false)
Create the sink
Give your sink a name, then click “Create Redis Sink”.
Verify & debug
To verify that your Redis sink is working:
- Make some changes in your source table
- Verify that the count of messages for your sink increases in the Sequin web console
- Using Redis CLI or another Redis client, check your stream:
You should see the messages from Sequin appear in the stream.
If messages don’t seem to be flowing:
- Click the “Messages” tab to view the state of messages for your sink
- Click any failed message
- Check the delivery logs for error details, including any Redis connection errors
Next steps
-
Setup a processor
Now that your Postgres data is flowing into Redis, you can setup a processor to read from the stream and process the data. See the Redis docs on
XREAD
.Refer to the Redis sink reference for the shape of messages that Sequin will publish to Redis.
-
Deploy your implementation
When you’re ready to deploy your implementation, see “How to deploy to production”.
-
Advanced configuration
For more about how Redis sinks work, see the Redis sink reference.
Was this page helpful?