Files
vercel__chat/packages/state-redis
github-actions[bot] a49a7f0b18 Version Packages (#26)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-01-23 22:41:41 -08:00
..
2026-01-04 09:12:45 -08:00
2026-01-23 22:41:41 -08:00
2026-01-23 22:41:41 -08:00
2026-01-02 14:20:41 -08:00
2025-12-21 20:48:14 -08:00
2025-12-21 20:48:14 -08:00
2025-12-21 20:48:14 -08:00

@chat-adapter/state-redis

Redis state adapter for the chat SDK using the official redis package.

Installation

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

Usage

import { Chat } from "chat";
import { createRedisState } from "@chat-adapter/state-redis";

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

Configuration

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

*Either url or client is required.

Using Connection URL

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

Using Existing Client

import { createClient } from "redis";

const client = createClient({ url: "redis://localhost:6379" });
await client.connect();

const state = createRedisState({ client });

Features

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

Key Structure

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

Production Recommendations

  • Use Redis 6.0+ for best performance
  • Enable Redis persistence (RDB or AOF)
  • Use Redis Cluster for high availability
  • Set appropriate memory limits

License

MIT