> Discover all available pages from the documentation index: https://mastra.ai/llms.txt

# Valkey

The Valkey storage implementation provides persistent storage and server-side caching through the [Valkey GLIDE](https://github.com/valkey-io/valkey-glide) client. Use it when your deployment runs Valkey or needs GLIDE features such as native Valkey configuration and authentication.

Use [`@mastra/redis`](https://mastra.ai/integrations/databases/redis) for Redis deployments that use the official `redis` client. The packages are tested independently against their respective servers.

## Installation

**npm**:

```bash
npm install @mastra/valkey
```

**pnpm**:

```bash
pnpm add @mastra/valkey
```

**Yarn**:

```bash
yarn add @mastra/valkey
```

**Bun**:

```bash
bun add @mastra/valkey
```

## Usage

```typescript
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:

```typescript
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 parameters

**id** (`string`): Unique identifier for the storage instance.

**host** (`string`): Valkey host address. Use with the direct connection fields.

**port** (`number`): Valkey port. (Default: `6379`)

**username** (`string`): Valkey authentication username. (Default: `default`)

**password** (`string`): Valkey authentication password.

**db** (`number`): Valkey database number. (Default: `0`)

**useTLS** (`boolean`): Enables TLS for direct connections.

**config** (`GlideClientConfiguration`): Native GLIDE standalone client configuration.

**client** (`GlideClient`): Preconfigured GLIDE standalone client.

**disableInit** (`boolean`): Disables automatic storage initialization.

Provide exactly one connection form: `client`, `config`, or `host` with its optional direct connection fields.

## Closing connections

Close clients created by `ValkeyStore` during graceful shutdown:

```typescript
await storage.close()
```

`close()` doesn't close an injected `GlideClient`.