Skip to main content

Overview

The Upstash Redis client provides several configuration options to customize behavior for your environment and use case. Configuration varies slightly between platforms, but all platforms share common options.

Basic configuration

Create a Redis client with your Upstash credentials:
Get your credentials from the Upstash Console under your database details.

Configuration from environment variables

Load credentials automatically from environment variables:
This method reads from:
  • UPSTASH_REDIS_REST_URL or KV_REST_API_URL for the URL
  • UPSTASH_REDIS_REST_TOKEN or KV_REST_API_TOKEN for the token
The KV_* variables provide compatibility with Vercel KV and other platforms that use different naming conventions.

Configuration options

Connection credentials

url
string
required
The REST URL for your Upstash Redis database. Find this in the Upstash Console under UPSTASH_REDIS_REST_URL.
token
string
required
The authentication token for your database. Find this in the Upstash Console under UPSTASH_REDIS_REST_TOKEN.

HTTP and retry options

retry
RetryConfig
default:"5 retries with exponential backoff"
Configure retry behavior for network errors.
Set to false to disable retries:
RetryConfig properties:
  • retries (number, default: 5): Maximum number of retry attempts
  • backoff (function): Function that returns wait time in milliseconds given the retry count
responseEncoding
false | 'base64'
default:"'base64'"
Controls how response data is encoded for transfer.By default, the server base64-encodes responses to safely handle non-UTF8 data like emojis. For very large responses with guaranteed UTF8 data, you can disable this:
Only disable base64 encoding if you’re certain your data is valid UTF8. Invalid data will cause parsing errors.
cache
CacheSetting
default:"'no-store'"
Configure HTTP cache behavior. Options: "default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload".
signal
AbortSignal | (() => AbortSignal)
Provide an AbortSignal to cancel in-flight requests.

Redis client options

automaticDeserialization
boolean
default:"true"
Automatically deserialize JSON responses from Redis using JSON.parse.
enableAutoPipelining
boolean
default:"true"
Enable automatic command pipelining for improved performance. See auto-pipeline for details.
readYourWrites
boolean
default:"true"
Ensure read-your-writes consistency. See read-your-writes for details.
latencyLogging
boolean
default:"false"
Log the latency of each command to the console for debugging.
enableTelemetry
boolean
default:"true"
Send anonymous telemetry data to help improve the SDK. Collected data includes SDK version, platform, and runtime version.Disable telemetry:
Or set the UPSTASH_DISABLE_TELEMETRY environment variable:

Node.js specific options

agent
unknown
Provide a custom HTTP agent for connection reuse (Node.js only).
This option is not supported in edge runtimes like Vercel Edge Functions or Cloudflare Workers.
keepAlive
boolean
default:"true"
Enable HTTP keep-alive for connection reuse.

Platform-specific imports

Cloudflare Workers

Import from the Cloudflare-specific entrypoint:

Node.js

Use the standard import:

Advanced: custom requester

For advanced use cases, provide a custom Requester implementation: