Files
Malte Ubl b27ea10bce READMEs
2026-01-02 14:20:41 -08:00

1.8 KiB

@chat-adapter/state-ioredis

Redis state adapter for the chat SDK using ioredis.

Installation

npm install chat @chat-adapter/state-ioredis ioredis

Usage

import { Chat } from "chat";
import { createIORedisState } from "@chat-adapter/state-ioredis";

const chat = new Chat({
  userName: "mybot",
  adapters: { /* ... */ },
  state: createIORedisState({
    url: process.env.REDIS_URL!,
  }),
});

Configuration

Option Required Description
url Yes* Redis connection URL
client No Existing ioredis client instance
keyPrefix No Prefix for all keys (default: "chat-sdk")

*Either url or client is required.

Using Connection URL

const state = createIORedisState({
  url: "redis://localhost:6379",
});

Using Existing Client

import Redis from "ioredis";

const client = new Redis("redis://localhost:6379");

const state = createIORedisState({ client });

When to Use ioredis vs redis

Use @chat-adapter/state-ioredis when:

  • You're already using ioredis in your project
  • You need Redis Cluster support
  • You need Redis Sentinel support
  • You prefer 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/Sentinel

Features

  • Thread subscriptions (persistent)
  • Distributed locking (works across instances)
  • Automatic reconnection
  • Redis Cluster support
  • Redis Sentinel support
  • Key prefix namespacing

Key Structure

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

License

MIT