Memory

In-memory state adapter for local development and tests. State is lost on restart and locks don't work across instances — never use it in production.

The memory adapter is for local development and testing only. State is lost on restart, and distributed locks don't work across multiple instances. Use @chat-adapter/state-redis, @chat-adapter/state-ioredis, or @chat-adapter/state-pg in production.

Install

pnpm add @chat-adapter/state-memory

Quick start

lib/bot.ts
import { Chat } from "chat";
import { createMemoryState } from "@chat-adapter/state-memory";

const bot = new Chat({
  userName: "mybot",
  adapters: { /* ... */ },
  state: createMemoryState(),
});

createMemoryState() takes no arguments. Subscriptions, locks, and cache live in the current process and disappear when the process exits.

When to use

  • Local development against pnpm --filter docs dev or your example app.
  • Unit tests that need a real StateAdapter interface without a Redis or Postgres dependency.
  • Quick prototypes where persistence isn't on the critical path.

Feature support

Capabilities

FeatureSupported
Persistence
Multi-instance
SubscriptionsIn-memory
Distributed lockingSingle process
Key-value cachingIn-memory
Lists
Queues
Automatic reconnect
Cluster support
Sentinel support
Key prefix namespacing

On this page