Looking for the chatbot template? It's now here.
GitHub

@chat-adapter/state-ioredis

Alternative Redis state adapter for Chat SDK using ioredis. Use this if you already have ioredis in your project or need Redis Cluster/Sentinel support.

Installation

bash
pnpm add @chat-adapter/state-ioredis

Usage

typescript
import { Chat } from "chat";import { createIORedisState } from "@chat-adapter/state-ioredis";const bot = new Chat({  userName: "mybot",  adapters: { /* ... */ },  state: createIORedisState({    url: process.env.REDIS_URL!,  }),});

Using an existing client

typescript
import Redis from "ioredis";const client = new Redis("redis://localhost:6379");const state = createIORedisState({ client });

Configuration

OptionRequiredDescription
urlYes*Redis connection URL
clientNoExisting ioredis client instance
keyPrefixNoPrefix for all keys (default: "chat-sdk")

*Either url or client is required.

When to use ioredis vs redis

Use @chat-adapter/state-ioredis when:

  • You already use ioredis in your project
  • You need Redis Cluster support
  • You need Redis Sentinel support
  • You prefer the ioredis API

Use @chat-adapter/state-redis when:

  • You want the official Redis client
  • You're starting a new project
  • You don't need Cluster or Sentinel

Key structure

{keyPrefix}:subscriptions     - SET of subscribed thread IDs{keyPrefix}:lock:{threadId}   - Lock key with TTL

Features

FeatureSupported
PersistenceYes
Multi-instanceYes
SubscriptionsYes
Distributed lockingYes
Key-value cachingYes
Automatic reconnectionYes
Redis Cluster supportYes
Redis Sentinel supportYes
Key prefix namespacingYes

License

MIT