Valkey
The Valkey storage implementation provides persistent storage and server-side caching through the Valkey GLIDE client. Use it when your deployment runs Valkey or needs GLIDE features such as native Valkey configuration and authentication.
Use @mastra/redis for Redis deployments that use the official redis client. The packages are tested independently against their respective servers.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/valkey
pnpm add @mastra/valkey
yarn add @mastra/valkey
bun add @mastra/valkey
UsageDirect link to Usage
import { Mastra } from '@mastra/core'
import { ValkeyStore } from '@mastra/valkey'
export const mastra = new Mastra({
storage: new ValkeyStore({
id: 'valkey-storage',
host: 'localhost',
port: 6379,
password: process.env.VALKEY_PASSWORD,
}),
})
You can also provide a native GLIDE configuration:
import { ValkeyStore } from '@mastra/valkey'
const storage = new ValkeyStore({
id: 'valkey-storage',
config: {
addresses: [{ host: 'localhost', port: 6379 }],
useTLS: true,
},
})
For an existing GlideClient, connect it before passing it to ValkeyStore. The caller remains responsible for closing injected clients.
Constructor parametersDirect link to Constructor parameters
id:
host?:
port?:
username?:
password?:
db?:
useTLS?:
config?:
client?:
disableInit?:
Provide exactly one connection form: client, config, or host with its optional direct connection fields.
Closing connectionsDirect link to Closing connections
Close clients created by ValkeyStore during graceful shutdown:
await storage.close()
close() doesn't close an injected GlideClient.