How to stream Postgres to Redis Strings
Build a real-time cache with Postgres change data capture (CDC) and Redis Strings. Learn to keep your Redis cache in sync with your database.
This guide shows you how to capture Postgres changes with Sequin and stream them to Redis as key-value pairs using Redis Strings.
With Postgres data flowing into Redis, you can build high-performance caches that automatically stay in sync with your database. This approach eliminates stale cache entries and provides sub-millisecond access to your data.
Prerequisites
To follow this guide, you need:
- A running Redis instance
- Sequin installed and configured
- A Postgres database connected to Sequin
If you haven’t set these up yet:
Create a Redis String sink
Navigate to Sinks
In the Sequin web console, go to Sinks → Create sink → Redis String.
Configure the source
Under Source:
- Select the database and table you want to cache
- Choose which actions to capture (
insert
,update
,delete
). You likely want to cache all actions - Optionally add filters to cache only specific rows
Set up initial backfill
Toggle Initial backfill if you want to initialize your Redis cache with all of the current data in your Postgres table.
You can choose to backfill again later via the Sequin web console or the management API.
Create a transform
Create a transform to define how your Postgres data is stored in Redis. The most common transform is to store the entire record as a JSON object:
For more selective caching, you can transform the data structure before storing it in Redis. For example, to cache only a few fields:
Configure Redis connection
Enter your Redis connection details:
- Host: Your Redis server address (e.g.,
localhost
orredis.example.com
) - Port: Redis port (default:
6379
) - Username/Password: If authentication is enabled
- Database: Redis database number (default:
0
) - TLS: Enable if your Redis server uses TLS
- Expire MS: Optional expiration time in milliseconds for cached keys
Test and create the sink
- Click Test Connection to verify Redis connectivity
- Name your sink (e.g.,
products-cache
) - Click Create Sink
Understanding key formats
By default, Sequin uses this key format in Redis:
For example, a product with ID 42 would be stored as:
For composite primary keys, values are joined with -
(ie. sequin:products:42-123
).
Verify your cache is working
-
Check that data is flowing by watching the Messages tab in the Sequin console
-
Query Redis to see your cached data:
-
Make a change in your Postgres database and verify it appears in Redis
Common caching patterns
Cache invalidation
Redis Strings sink automatically handles cache invalidation:
- Inserts and updates result in
SET
operations - Deletes result in
DEL
operations
You don’t need to implement your own cache invalidation logic.
TTL-based caching
Set expire_ms
to automatically expire keys after a specific period:
expire_ms: 86400000
=> 24-hour cacheexpire_ms: 3600000
=> 1-hour cache
This is most useful to save only recently inserted or updated data in Redis, for instance if you want to reduce memory usage.
We otherwise recommend infinite TTL because Sequin automatically removes deleted records from Redis, as long as delete
actions are enabled in the sink configuration.
Next steps
To enhance your Redis caching system: