Redis
Production state adapter for Chat SDK using the official `redis` client, with persistent subscriptions, distributed locking, and a key-value cache.
Create a new bot
Scaffold a Next.js bot that stores state in Redis with create-chat-sdk. Replace slack with your platform adapter:
pnpm create chat-sdk@latest my-bot --adapter slack redis -yThe CLI adds @chat-adapter/state-redis, wires createRedisState() into src/lib/bot.ts, and lists REDIS_URL in .env.example. To add the adapter to an existing app, start at Install.
Install
pnpm add @chat-adapter/state-redisQuick start
With no options, createRedisState() connects to the URL in REDIS_URL.
If you already use ioredis or need Redis Sentinel, see when to choose ioredis vs redis.
Vercel Marketplace
Upstash Redis and Redis Cloud are both available on the Vercel Marketplace. From your project directory, link the project and add an integration with the Vercel CLI. vercel integration add creates the database, connects it to the linked project, adds its credentials as environment variables, and pulls them into your local env file.
Upstash Redis adds REDIS_URL to your project, and createRedisState() reads it with no extra configuration. If your provider stores the connection URL under another name, pass that variable as url.
Configuration
Prop
Type
Either url, the REDIS_URL env var, or client is required.
Environment variables
| Variable | Required | Description |
|---|---|---|
REDIS_URL | Unless url or client is set | Redis connection URL, used when url is not passed. |
Using an existing client
Pass a client you created with the redis package as client. The adapter doesn't connect a client it didn't create, so call client.connect() yourself before the bot starts. The adapter's disconnect() leaves the client open.
Data model
Every key starts with keyPrefix, which defaults to "chat-sdk". Set your own prefix to keep the bot's keys apart from other data in the same Redis database:
| Key | Redis type | Contents |
|---|---|---|
{keyPrefix}:subscriptions | Set | Subscribed thread IDs |
{keyPrefix}:lock:{threadId} | String | Lock token, with a TTL |
{keyPrefix}:cache:{key} | String | JSON-serialized cache value, with an optional TTL |
{keyPrefix}:list:{key} | List | JSON-serialized list entries, with an optional TTL |
{keyPrefix}:queue:{threadId} | List | Queued messages for a thread, with a TTL |
Production notes
- Run Redis 6.0+ for best performance.
- Enable persistence (RDB or AOF).
- Set explicit memory limits.
- For Redis Sentinel, use
@chat-adapter/state-ioredis. This adapter accepts a singleredisclient. Neither adapter supports Redis Cluster.
For serverless deployments such as Vercel or AWS Lambda, use a serverless-compatible Redis provider. On Vercel, you can provision Upstash Redis or Redis Cloud from the Vercel Marketplace.
Feature support
Capabilities
| Feature | Supported |
|---|---|
| Persistence | |
| Multi-instance | |
| Subscriptions | |
| Distributed locking | |
| Key-value caching | TTL |
| Lists | |
| Queues | |
| Automatic reconnect | |
| Cluster support | |
| Sentinel support | |
| Key prefix namespacing |