An open API service indexing awesome lists of open source software.

https://github.com/rubix-studios-pty-ltd/payload-upstash

This package provides a way to use Upstash Redis as a KV adapter with Payload.
https://github.com/rubix-studios-pty-ltd/payload-upstash

kv-store payload payload-plugin payloadcms payloadcms-v3 redis upstash upstash-redis

Last synced: 4 months ago
JSON representation

This package provides a way to use Upstash Redis as a KV adapter with Payload.

Awesome Lists containing this project

README

          

# PayloadCMS + Upstash KV Adapter

This package provides a way to use [Upstash](https://upstash.com) as a KV adapter with Payload.

## Installation

```sh
pnpm add @rubixstudios/payload-upstash
```

## Usage

```ts
import { upstashKVAdapter } from '@rubixstudios/payload-upstash'

export default buildConfig({
collections: [Media],
kv: upstashKVAdapter({
// Upstash connection URL. Defaults to process.env.UPSTASH_URL
url: process.env.UPSTASH_URL!,
token: process.env.UPSTASH_TOKEN!,
// Optional prefix for Upstash Redis keys to isolate the store. Defaults to 'payload-kv:'
keyPrefix: 'kv-storage:',
// Optional TTL configuration for automatic expiration by key prefix
ttl: [
{ prefix: 'session:', ttl: 3600 },
{ prefix: 'cache:', ttl: 300 },
{ prefix: 'temp:', ttl: 60 },
],
}),
})
```

Then you can access the KV storage using `payload.kv`:

```ts
await payload.kv.set('key', { value: 1 })
const data = await payload.kv.get('key')
payload.logger.info(data)
```