ioredis
Redis state adapter for Chat SDK built on ioredis. Use it if you already depend on ioredis or need Redis Sentinel.
Create a new bot
Scaffold a Next.js bot that stores state in Redis through ioredis with create-chat-sdk. Replace slack with your platform adapter:
pnpm create chat-sdk@latest my-bot --adapter slack ioredis -yThe CLI adds @chat-adapter/state-ioredis, wires createIoRedisState({ url: process.env.REDIS_URL }) 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-ioredisQuick start
To provision Upstash Redis or Redis Cloud for a Vercel project with the Vercel CLI, see Vercel Marketplace on the Redis adapter page. The same connection URL works with this adapter.
When to choose ioredis vs redis
Both adapters implement the same state operations with the same key layout. The difference is the Redis client underneath.
Use @chat-adapter/state-ioredis when:
- You already use ioredis in your project.
- You need Redis Sentinel. Pass a Sentinel-configured
Redisclient asclient. - You prefer the ioredis API.
Use @chat-adapter/state-redis when:
- You want the official
redisclient. - You're starting a new project and don't need Sentinel.
Neither adapter supports Redis Cluster. The ioredis adapter's client option accepts a Redis instance, and an ioredis Cluster doesn't satisfy that type.
Configuration
Prop
Type
Either url or client is required.
Environment variables
The adapter doesn't read environment variables itself, so pass the URL in your code.
| Variable | Required | Description |
|---|---|---|
REDIS_URL | No | Redis connection URL. The quick start reads it and passes it as url. |
Using an existing client
Pass an ioredis client as client. ioredis connects on its own, and the adapter's disconnect() doesn't quit a client it didn't create.
Data model
Every key starts with keyPrefix, which defaults to "chat-sdk". The layout matches @chat-adapter/state-redis.
| 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 |
Feature support
Capabilities
| Feature | Supported |
|---|---|
| Persistence | |
| Multi-instance | |
| Subscriptions | |
| Distributed locking | |
| Key-value caching | |
| Lists | |
| Queues | |
| Automatic reconnect | |
| Cluster support | |
| Sentinel support | |
| Key prefix namespacing |