Memory
In-memory state adapter for local development and tests. State is lost on restart and locks don't work across instances, so don't use it in production.
Create a new bot
Scaffold a Next.js bot that uses the Memory state adapter with create-chat-sdk. Replace slack with your platform adapter:
pnpm create chat-sdk@latest my-bot --adapter slack memory -yTo add the adapter to an existing app, start at Install.
Install
pnpm add @chat-adapter/state-memoryQuick start
createMemoryState() takes no arguments. Subscriptions, locks, cache entries, lists, and queues live in the current process and disappear when the process exits.
Use it for local development and for tests that need a real StateAdapter without a Redis or Postgres dependency.
Limitations
Everything the adapter stores lives in one process's memory. In production, that leads to these problems:
- State doesn't survive a restart or redeploy. Thread subscriptions, thread state from
setState(), and queued messages are lost, so new messages in previously subscribed threads no longer reachonSubscribedMessage. - State isn't shared between instances. A thread subscribed on one instance looks unsubscribed on another, and deduplication only catches repeat deliveries that reach the same instance.
- Locks only apply within one process. Two instances can acquire the lock for the same thread and handle messages in it at the same time.
When NODE_ENV is production, connect() logs a warning that the memory adapter isn't recommended for production. For production, use @chat-adapter/state-redis, @chat-adapter/state-ioredis, or @chat-adapter/state-pg.
Feature support
Capabilities
| Feature | Supported |
|---|---|
| Persistence | |
| Multi-instance | |
| Subscriptions | In-memory |
| Distributed locking | Single process |
| Key-value caching | In-memory |
| Lists | |
| Queues | |
| Automatic reconnect | |
| Cluster support | |
| Sentinel support | |
| Key prefix namespacing |