Skip to main content
This guide covers the fundamental Redis operations using the Upstash Redis SDK. Learn how to work with strings, hashes, lists, sets, sorted sets, and JSON data.

Installation

Initialize the Client

Alternatively, use fromEnv() to automatically load credentials from environment variables:

Strings

Strings are the most basic Redis data type, representing a sequence of bytes.

Set and Get

Set with Expiration

Increment and Decrement

Multiple Keys

Hashes

Hashes are maps between string fields and string values, perfect for representing objects.

Set and Get Hash Fields

Get Multiple Fields

Hash Operations

Lists

Lists are ordered collections of strings, sorted by insertion order.

Push and Pop

Range Operations

Other List Operations

Sets

Sets are unordered collections of unique strings.

Add and Remove Members

Set Operations

Sorted Sets

Sorted sets are similar to sets but each member has an associated score used for ordering.

Add Members with Scores

Query Sorted Sets

Sorted Set Operations

JSON

The JSON data type allows you to store, update, and retrieve JSON values.

Set and Get JSON

Update JSON Fields

Array Operations

Numeric Operations

Key Management

Check Existence and Delete

Set Expiration

Get Key Information

Next Steps

AWS Lambda

Deploy Redis with AWS Lambda functions

Cloudflare Workers

Use Redis in Cloudflare Workers

Next.js

Integrate Redis with Next.js applications

API Reference

Explore all available Redis commands