Upstash Redis Integration
Upstash provides serverless Redis.
Guidelines
- •Use the
@upstash/redispackage to interact with Upstash Redis. - •The integration uses the
KV_REST_API_URLandKV_REST_API_TOKENenvironment variables.
Environment Variables
- •
KV_REST_API_URL- Upstash Redis REST API URL - •
KV_REST_API_TOKEN- Upstash Redis REST API token
Example Usage
typescript
import { Redis } from '@upstash/redis'
const redis = new Redis({
url: process.env.KV_REST_API_URL,
token: process.env.KV_REST_API_TOKEN,
})
// Set a value
await redis.set('key', 'value')
// Get a value
const value = await redis.get('key')
// Set with expiration (seconds)
await redis.set('session', sessionData, { ex: 3600 })
// Increment
await redis.incr('counter')