Skip to main content
The Redis class is the main entry point for interacting with Upstash Redis. It provides methods for all Redis commands and supports both direct instantiation and environment-based configuration.

Constructor

With Configuration Object

Create a new Redis client by providing connection credentials.
config
RedisConfigNodejs
required
Configuration object for the Redis client

With Custom Requester

Create a Redis client with a custom HTTP requester implementation.
requester
Requester
required
Custom requester implementation

Static Methods

fromEnv()

Create a Redis instance from environment variables.
This method automatically loads connection credentials from:
  • UPSTASH_REDIS_REST_URL or KV_REST_API_URL (fallback for Vercel KV)
  • UPSTASH_REDIS_REST_TOKEN or KV_REST_API_TOKEN (fallback for Vercel KV)
config
Omit<RedisConfigNodejs, 'url' | 'token'>
Optional configuration (all options except url and token)
redis
Redis
A configured Redis instance

Properties

readYourWritesSyncToken

Get or set the sync token for read-your-writes consistency.
readYourWritesSyncToken
string | undefined
The current sync token

Instance Methods

pipeline()

Create a new pipeline to batch multiple commands.
pipeline
Pipeline
A new Pipeline instance for batching commands
See Pipeline for full documentation.

multi()

Create a transaction (MULTI/EXEC) to execute commands atomically.
multi
Pipeline
A new Pipeline instance configured for atomic execution

createScript()

Create a Lua script that can be executed efficiently using EVALSHA.
script
string
required
The Lua script to execute
opts
{ readonly?: boolean }
Script options
script
Script<TResult> | ScriptRO<TResult>
A Script or ScriptRO instance depending on the readonly option
See Script for full documentation.

use()

Wrap middleware around the HTTP client for custom request/response handling.
middleware
(request: UpstashRequest, next: (req: UpstashRequest) => Promise<UpstashResponse<TResult>>) => Promise<UpstashResponse<TResult>>
required
Middleware function to wrap around requests

Command Methods

The Redis class provides methods for all Redis commands. Here are some commonly used examples:

String Commands

Hash Commands

List Commands

Set Commands

Sorted Set Commands

JSON Commands

Key Management

Complete Example

TypeScript Support

The Redis client is fully typed with TypeScript generics: