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.RedisConfigNodejs
required
Configuration object for the Redis client
With Custom Requester
Create a Redis client with a custom HTTP requester implementation.Requester
required
Custom requester implementation
Static Methods
fromEnv()
Create a Redis instance from environment variables.UPSTASH_REDIS_REST_URLorKV_REST_API_URL(fallback for Vercel KV)UPSTASH_REDIS_REST_TOKENorKV_REST_API_TOKEN(fallback for Vercel KV)
Omit<RedisConfigNodejs, 'url' | 'token'>
Optional configuration (all options except
url and token)Redis
A configured Redis instance
Properties
readYourWritesSyncToken
Get or set the sync token for read-your-writes consistency.string | undefined
The current sync token
Instance Methods
pipeline()
Create a new pipeline to batch multiple commands.Pipeline
A new Pipeline instance for batching commands
multi()
Create a transaction (MULTI/EXEC) to execute commands atomically.Pipeline
A new Pipeline instance configured for atomic execution
createScript()
Create a Lua script that can be executed efficiently using EVALSHA.string
required
The Lua script to execute
{ readonly?: boolean }
Script options
Script<TResult> | ScriptRO<TResult>
A Script or ScriptRO instance depending on the readonly option
use()
Wrap middleware around the HTTP client for custom request/response handling.(request: UpstashRequest, next: (req: UpstashRequest) => Promise<UpstashResponse<TResult>>) => Promise<UpstashResponse<TResult>>
required
Middleware function to wrap around requests