Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
Upstash
https://github.com/upstash/docs
Admin
Upstash documentation
Tokens:
1,828,744
Snippets:
15,818
Trust Score:
10
Update:
1 hour ago
Context
Chat
Benchmark
73.95
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
================ LIBRARY RULES ================ - **Need a Redis database fast?** Skip the signup and dashboard — POST to [`https://upstash.com/start-redis`](https://upstash.com/start-redis) to get an endpoint and token. The database expires in 72 hours, but you can claim it with your Upstash account ================ CODE SNIPPETS ================ ### Create Next.js app and install QStash Source: https://github.com/upstash/docs/blob/main/qstash/quickstarts/vercel-nextjs.mdx Commands to scaffold a Next.js app, install the QStash package, and start the development server. ```bash npx create-next-app@latest qstash-bg-job ``` ```bash cd qstash-bg-job ``` ```bash npm install @upstash/qstash ``` ```bash npm run dev ``` -------------------------------- ### Deploy to Vercel Source: https://github.com/upstash/docs/blob/main/qstash/quickstarts/vercel-nextjs.mdx Commands to install the Vercel CLI and deploy the application to get a public URL. ```bash npm install -g vercel ``` ```bash vercel ``` -------------------------------- ### Install blob-go with go get Source: https://github.com/upstash/docs/blob/main/blob/overall/quickstart.mdx Install the Go server SDK. For Go apps, also install @upstash/blob for the browser side. ```bash go get github.com/upstash/blob-go ``` -------------------------------- ### Install qstash via pip Source: https://github.com/upstash/docs/blob/main/qstash/sdks/py/gettingstarted.mdx Install the QStash Python SDK from PyPI using pip. ```bash pip install qstash ``` -------------------------------- ### Install Upstash Realtime with bun Source: https://github.com/upstash/docs/blob/main/realtime/overall/quickstart.mdx Install the required packages using bun. This is the first step in the quickstart. ```bash bun install @upstash/realtime @upstash/redis zod ``` -------------------------------- ### Run OpenClaw Onboarding Wizard Source: https://github.com/upstash/docs/blob/main/box/guides/openclaw-setup.mdx Starts the interactive onboarding wizard. The CLI will guide you through provider selection, authentication, and gateway configuration. Follow the prompts to complete setup; copy the dashboard URL with its token for later use. ```bash openclaw onboard --install-daemon ``` -------------------------------- ### Get help for any command Source: https://github.com/upstash/docs/blob/main/agent-resources/cli.mdx Use --help on any command or subcommand for details. ```bash upstash --help upstash redis --help upstash redis create --help ``` -------------------------------- ### Install Upstash Realtime with yarn Source: https://github.com/upstash/docs/blob/main/realtime/overall/quickstart.mdx Install the required packages using yarn. This is the first step in the quickstart. ```bash yarn add @upstash/realtime @upstash/redis zod ``` -------------------------------- ### Install @upstash/blob with bun Source: https://github.com/upstash/docs/blob/main/blob/overall/quickstart.mdx Install the JavaScript/TypeScript SDK using bun. ```bash bun add @upstash/blob ``` -------------------------------- ### Run Upstash setup interactively Source: https://github.com/upstash/docs/blob/main/agent-resources/cli.mdx Runs the Upstash setup wizard. With no arguments, it starts `upstash setup` in a terminal, asking where to install and which agents to set up. From an agent or script, call `upstash setup` explicitly. ```bash npx upstash ``` -------------------------------- ### Install Upstash Box SDK with bun Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Install the Upstash Box SDK using bun. ```bash bun install @upstash/box ``` -------------------------------- ### Install upstash-blob with uv Source: https://github.com/upstash/docs/blob/main/blob/overall/quickstart.mdx Install the Python server SDK using uv. ```bash uv add upstash-blob ``` -------------------------------- ### GET example with go-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Creates a Redis client from the REDIS_URL environment variable and gets the value of 'my-key'. Panics on connection or command errors. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.Get(context.Background(), "my-key").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Install Upstash Realtime with npm Source: https://github.com/upstash/docs/blob/main/realtime/overall/quickstart.mdx Install the required packages using npm. This is the first step in the quickstart. ```bash npm install @upstash/realtime @upstash/redis zod ``` -------------------------------- ### Install @upstash/qstash via npm Source: https://github.com/upstash/docs/blob/main/qstash/sdks/ts/gettingstarted.mdx Install the QStash TypeScript SDK using npm. ```bash npm install @upstash/qstash ``` -------------------------------- ### Install Upstash Realtime with pnpm Source: https://github.com/upstash/docs/blob/main/realtime/overall/quickstart.mdx Install the required packages using pnpm. This is the first step in the quickstart. ```bash pnpm add @upstash/realtime @upstash/redis zod ``` -------------------------------- ### GET example with redis-py Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Creates a Redis client from the REDIS_URL environment variable and gets the value of 'my-key'. ```python import os import redis client = redis.from_url(os.environ["REDIS_URL"]) result = client.get("my-key") print(result) ``` -------------------------------- ### Install Upstash Box SDK with pnpm Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Install the Upstash Box SDK using pnpm. ```bash pnpm add @upstash/box ``` -------------------------------- ### Install Django and Upstash Redis Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/django.mdx Install the required Python packages for the Django quickstart. ```shell pip install django pip install upstash-redis ``` -------------------------------- ### Install Upstash Box SDK with yarn Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Install the Upstash Box SDK using yarn. ```bash yarn add @upstash/box ``` -------------------------------- ### Install required packages Source: https://github.com/upstash/docs/blob/main/workflow/agents/getting-started.mdx Install the Upstash Workflow, workflow agents, AI SDK, and Zod packages needed for the agent example. ```bash npm i @upstash/workflow @upstash/workflow-agents ai zod ``` -------------------------------- ### Complete Setup Source: https://github.com/upstash/docs/blob/main/redis/sdks/py/commands/connection/client_setinfo.mdx Sets both library name and version, and notes that this information will appear in CLIENT LIST output. ```py # Set both library name and version redis.client_setinfo("LIB-NAME", "my-redis-wrapper") redis.client_setinfo("LIB-VER", "3.2.1") # Now this information will appear in CLIENT LIST output ``` -------------------------------- ### Install @upstash/blob with yarn Source: https://github.com/upstash/docs/blob/main/blob/overall/quickstart.mdx Install the JavaScript/TypeScript SDK using yarn. ```bash yarn add @upstash/blob ``` -------------------------------- ### GET example with ioredis Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Creates a Redis client using the REDIS_URL environment variable and gets the value of 'my-key'. ```ts import Redis from "ioredis"; const redis = new Redis(process.env.REDIS_URL!); const result = await redis.get("my-key"); console.log(result); ``` -------------------------------- ### Install @upstash/redis with pnpm Source: https://github.com/upstash/docs/blob/main/redis/sdks/ts/getstarted.mdx Install the @upstash/redis package using pnpm. ```bash pnpm add @upstash/redis ``` -------------------------------- ### Install @upstash/redis with yarn Source: https://github.com/upstash/docs/blob/main/redis/sdks/ts/getstarted.mdx Install the @upstash/redis package using yarn. ```bash yarn add @upstash/redis ``` -------------------------------- ### Run setup.py Source: https://github.com/upstash/docs/blob/main/box/guides/browser-use.mdx Executes the setup script that creates the box and schedules the agent. ```bash python setup.py ``` -------------------------------- ### Install @upstash/ratelimit with npm Source: https://github.com/upstash/docs/blob/main/redis/sdks/ratelimit-ts/gettingstarted.mdx Install the @upstash/ratelimit package using npm. ```bash npm install @upstash/ratelimit ``` -------------------------------- ### ZINTERSTORE example with Redis CLI Source: https://github.com/upstash/docs/blob/main/redis/commands/sorted-set/zinterstore.mdx Basic command example using the Redis CLI. ```bash ZINTERSTORE destination-key 1 my-key ``` -------------------------------- ### Start Trial in Stripe (Python) Source: https://github.com/upstash/docs/blob/main/workflow/examples/authWebhook.mdx Starts a trial in Stripe using context.run. ```python async def _start_trial_in_stripe() -> None: await start_trial_in_stripe(email) await context.run("start trial in Stripe", _start_trial_in_stripe) ``` -------------------------------- ### Install @upstash/blob with pnpm Source: https://github.com/upstash/docs/blob/main/blob/overall/quickstart.mdx Install the JavaScript/TypeScript SDK using pnpm. ```bash pnpm add @upstash/blob ``` -------------------------------- ### Install upstash-ratelimit with pip Source: https://github.com/upstash/docs/blob/main/redis/sdks/ratelimit-py/gettingstarted.mdx Install the upstash-ratelimit Python package using pip. ```bash pip install upstash-ratelimit ``` -------------------------------- ### Install Upstash Box SDK with npm Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Install the Upstash Box SDK using npm. ```bash npm install @upstash/box ``` -------------------------------- ### GET example with jedis Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Creates a Jedis client from the REDIS_URL environment variable and gets the value of 'my-key'. ```java import java.net.URI; import redis.clients.jedis.Jedis; try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { Object result = jedis.get("my-key"); System.out.println(result); } ``` -------------------------------- ### Install Upstash Box SDK with pip Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Install the Upstash Box SDK using pip. ```bash pip install upstash-box ``` -------------------------------- ### Install @upstash/vector with pnpm Source: https://github.com/upstash/docs/blob/main/vector/sdks/ts/getting-started.mdx Install the Upstash Vector TypeScript SDK using pnpm. ```shell pnpm add @upstash/vector ``` -------------------------------- ### Initialize SAM application with sam init Source: https://github.com/upstash/docs/blob/main/redis/tutorials/using_aws_sam.mdx Run sam init and select the Hello World Example template with Python and zip package type, disabling X-Ray, CloudWatch Application Insights, and Structured Logging. ```shell ➜ tutorials > ✗ sam init Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: 1 Choose an AWS Quick Start application template 1 - Hello World Example 2 - Data processing 3 - Hello World Example with Powertools for AWS Lambda 4 - Multi-step workflow 5 - Scheduled task 6 - Standalone function 7 - Serverless API 8 - Infrastructure event management 9 - Lambda Response Streaming 10 - Serverless Connector Hello World Example 11 - Multi-step workflow with Connectors 12 - GraphQLApi Hello World Example 13 - Full Stack 14 - Lambda EFS example 15 - DynamoDB Example 16 - Machine Learning Template: 1 Use the most popular runtime and package type? (Python and zip) [y/N]: y Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: N Would you like to enable monitoring using CloudWatch Application Insights? For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: N Would you like to set Structured Logging in JSON format on your Lambda functions? [y/N]: N ``` -------------------------------- ### Create a new TanStack Start project Source: https://github.com/upstash/docs/blob/main/workflow/quickstarts/tanstack-start.mdx Run this command to scaffold a new TanStack Start project. After creation, navigate into the project directory. ```bash pnpm create @tanstack/start@latest ``` ```bash cd your-project-name ``` -------------------------------- ### Install @upstash/vector with npm Source: https://github.com/upstash/docs/blob/main/vector/sdks/ts/getting-started.mdx Install the Upstash Vector TypeScript SDK using npm. ```shell npm install @upstash/vector ``` -------------------------------- ### GET example with redis-rs Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Creates a Redis client from the REDIS_URL environment variable and gets the value of 'my-key'. ```rust use redis::TypedCommands; fn main() -> redis::RedisResult<()> { let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); let client = redis::Client::open(url)?; let mut connection = client.get_connection()?; let result = connection.get("my-key")?; println!("{result:?}"); Ok(()) } ``` -------------------------------- ### Install upstash-vector via pip Source: https://github.com/upstash/docs/blob/main/vector/sdks/py/gettingstarted.mdx Install the upstash-vector Python SDK from PyPI. ```bash pip install upstash-vector ``` -------------------------------- ### Install upstash-redis via pip Source: https://github.com/upstash/docs/blob/main/redis/sdks/py/gettingstarted.mdx Install the upstash-redis package from PyPI using pip. ```bash pip install upstash-redis ``` -------------------------------- ### GET example with Redis CLI Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Simple command to get the value of 'my-key' using the Redis CLI. ```bash GET my-key ``` -------------------------------- ### Create a Box with initCommand (Python) Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Create a Box that runs a startup script (init_command) each time the box starts. The command runs from /workspace/home. ```python box = Box.create( runtime="node", init_command="""node -e 'require("http").createServer((_, res) => res.end("Hello from Box!")).listen(3000)'""", ) ``` -------------------------------- ### Install upstash/vector with Composer Source: https://github.com/upstash/docs/blob/main/vector/sdks/php/getting-started.mdx Install the PHP SDK for Upstash Vector using Composer. ```shell composer require upstash/vector ``` -------------------------------- ### Start TanStack Start Development Server with pnpm Source: https://github.com/upstash/docs/blob/main/workflow/quickstarts/tanstack-start.mdx Starts the TanStack Start development server using pnpm. The app runs on http://localhost:3000 after execution. ```bash pnpm dev ``` -------------------------------- ### go-redis Example Source: https://github.com/upstash/docs/blob/main/redis/commands/set/sismember.mdx Example using the go-redis client. It parses the REDIS_URL, creates a client, and checks membership with SIsMember. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.SIsMember(context.Background(), "my-key", "member").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Install @upstash/search with bun Source: https://github.com/upstash/docs/blob/main/search/sdks/ts/getting-started.mdx Install the Upstash Search TypeScript SDK using bun. ```bash bun install @upstash/search ``` -------------------------------- ### Start Trial in Stripe (TypeScript) Source: https://github.com/upstash/docs/blob/main/workflow/examples/authWebhook.mdx Starts a trial in Stripe using context.run. ```typescript await context.run("start trial in Stripe", async () => { await startTrialInStripe(email); }); ``` -------------------------------- ### go-redis Example Source: https://github.com/upstash/docs/blob/main/redis/commands/list/lpushx.mdx Example using the go-redis client. It parses REDIS_URL, creates a client, and calls LPushX to push an element if the key exists, printing the result. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.LPushX(context.Background(), "my-key", "element").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Install @upstash/search with pnpm Source: https://github.com/upstash/docs/blob/main/search/sdks/ts/getting-started.mdx Install the Upstash Search TypeScript SDK using pnpm. ```bash pnpm add @upstash/search ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/upstash/docs/blob/main/realtime/overall/quickstart.mdx Add your Upstash Redis credentials to the .env file. Replace the example values with your own from the Upstash Console. ```bash UPSTASH_REDIS_REST_URL=https://striking-osprey-20681.upstash.io UPSTASH_REDIS_REST_TOKEN=AVDJAAIjcDEyZ... ``` -------------------------------- ### Install @upstash/search with yarn Source: https://github.com/upstash/docs/blob/main/search/sdks/ts/getting-started.mdx Install the Upstash Search TypeScript SDK using yarn. ```bash yarn add @upstash/search ``` -------------------------------- ### Example .env with Box and Neon credentials Source: https://github.com/upstash/docs/blob/main/box/guides/neon-ai-gateway.mdx Shows the required environment variables: your Box API key, Neon AI Gateway token, and the branch gateway URL. Add your Box API key next to the Neon values. ```bash UPSTASH_BOX_API_KEY=box_xxxxxxxxxxxxxxxxxxxxxxxx NEON_AI_GATEWAY_TOKEN=nt_live_xxxxxxxxxxxxxxxx NEON_AI_GATEWAY_BASE_URL=https://br-<name>-api.ai.<cell>.<region>.aws.neon.tech ``` -------------------------------- ### Install @upstash/search with npm Source: https://github.com/upstash/docs/blob/main/search/sdks/ts/getting-started.mdx Install the Upstash Search TypeScript SDK using npm. ```bash npm install @upstash/search ``` -------------------------------- ### Initialize Node project and install ioredis Source: https://github.com/upstash/docs/blob/main/redis/tutorials/aws_app_runner_with_redis.mdx Commands to initialize a Node.js project and install the ioredis client for connecting to Redis. ```bash npm init npm install ioredis ``` -------------------------------- ### Install upstash-search with pip Source: https://github.com/upstash/docs/blob/main/search/sdks/py/gettingstarted.mdx Install the Python SDK for Upstash AI Search using pip. ```bash pip install upstash-search ``` -------------------------------- ### upstash qstash get Source: https://github.com/upstash/docs/blob/main/agent-resources/cli.mdx Retrieves details of a specific QStash resource by its ID. ```APIDOC ## [CLI] upstash qstash get ### Description Retrieves details of a specific QStash resource by its ID. ### Command `upstash qstash get --qstash-id $QSTASH_ID` ### Parameters #### Options - **--qstash-id** (string) - Required - The ID of the QStash resource. ### Example ```bash upstash qstash get --qstash-id $QSTASH_ID ``` ``` -------------------------------- ### Create and navigate to demo directory Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/koyeb.mdx Creates a new directory for the demo application and navigates into it. ```bash mkdir example-koyeb-upstash cd example-koyeb-upstash ``` -------------------------------- ### New User Signup - Send Welcome Email (Python) Source: https://github.com/upstash/docs/blob/main/workflow/examples/customerOnboarding.mdx Sends a welcome email to a newly signed-up user using context.run. This is the Python equivalent of the TypeScript example. ```python async def _new_signup() -> None: await send_email("Welcome to the platform", email) await context.run("new-signup", _new_signup) ``` -------------------------------- ### upstash blob get Source: https://github.com/upstash/docs/blob/main/agent-resources/cli.mdx Retrieves details of a specific Blob bucket, optionally hiding credentials. ```APIDOC ## [CLI] upstash blob get ### Description Retrieves details of a specific Blob bucket, optionally hiding credentials. ### Command `upstash blob get --bucket-id $BUCKET_ID [--hide-credentials]` ### Parameters #### Options - **--bucket-id** (string) - Required - The ID of the Blob bucket. - **--hide-credentials** (flag) - Optional - Omit token and token_next from the output. ### Example ```bash upstash blob get --bucket-id $BUCKET_ID upstash blob get --bucket-id $BUCKET_ID --hide-credentials ``` ``` -------------------------------- ### Import @upstash/redis in Deno Source: https://github.com/upstash/docs/blob/main/redis/sdks/ts/getstarted.mdx In Deno, import @upstash/redis directly from npm without an install step. ```ts import { Redis } from "npm:@upstash/redis"; ``` -------------------------------- ### Initialize Node project and install dependencies Source: https://github.com/upstash/docs/blob/main/redis/tutorials/cloud_run_sessions.mdx Commands to initialize a Node project and install express, redis, connect-redis, and express-session. ```bash npm init npm install express redis connect-redis express-session ``` -------------------------------- ### upstash redis get Source: https://github.com/upstash/docs/blob/main/agent-resources/cli.mdx Retrieves details of a specific Redis database by its ID. Optionally hides credentials in the output. ```APIDOC ## [CLI] upstash redis get ### Description Retrieves details of a specific Redis database by its ID. Optionally hides credentials in the output. ### Command `upstash redis get --db-id $DB_ID [--hide-credentials]` ### Parameters #### Command Options - `--db-id` (string) - Required - The ID of the Redis database. - `--hide-credentials` (flag) - Optional - If set, hides credentials in the output. ### Response No response example provided. ``` -------------------------------- ### Python examples for $boost Source: https://github.com/upstash/docs/blob/main/redis/search/query-operators/boolean-operators/boost.mdx Two Python query examples: one boosts wireless and in-stock items, another demotes budget items with a negative boost. ```python # Prioritize wireless and in-stock items products.query(filter={ "$must": {"name": "headphones"}, "$should": {"description": "wireless", "inStock": True, "$boost": 5.0}, }) # Demote budget items without excluding them products.query(filter={ "$must": {"category": "electronics"}, "$should": {"description": "budget", "$boost": -1.0}, }) ``` -------------------------------- ### Install blob-go Source: https://github.com/upstash/docs/blob/main/blob/sdks/go/overview.mdx Install the Go SDK using the go get command. The SDK requires Go 1.22 or later and uses only the standard library. ```APIDOC ## Install ```bash go get github.com/upstash/blob-go ``` It needs Go 1.22 or later and uses only the standard library. ```go import blob "github.com/upstash/blob-go" ``` The package name is `blob`. The examples import it under that name explicitly, since the module path ends in `blob-go`. ``` -------------------------------- ### Run sync and async Redis commands Source: https://github.com/upstash/docs/blob/main/redis/sdks/py/gettingstarted.mdx Example of running set and get commands in sync and async contexts. In serverless environments, initialize the client outside the request handler to reuse it while the function is hot. ```python from upstash_redis import Redis redis = Redis.from_env() def main(): redis.set("a", "b") print(redis.get("a")) # or for async context: from upstash_redis.asyncio import Redis redis = Redis.from_env() async def main(): await redis.set("a", "b") print(await redis.get("a")) ``` -------------------------------- ### LSET Example with go-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/list/lset.mdx Example using the go-redis client. Parses the REDIS_URL environment variable, creates a client, sets the element at index 0 of 'my-key' to 'element', and prints the result. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.LSet(context.Background(), "my-key", 0, "element").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Expected console logs from agent run Source: https://github.com/upstash/docs/blob/main/workflow/agents/getting-started.mdx Example logs showing the agent's inner thought and final response after running the workflow. ```text Inner thought: I will discuss the future of space exploration and the potential advancements in technology and missions. Final response: The future of space exploration holds exciting possibilities with advancements in technology, potential manned missions to Mars, increased commercial space travel, and exploration of distant celestial bodies. ``` -------------------------------- ### ZINTERSTORE example with go-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/sorted-set/zinterstore.mdx Example using the go-redis Go client. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.ZInterStore(context.Background(), "destination-key", &redis.ZStore{Keys: []string{"my-key"}}).Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Successful response JSON Source: https://github.com/upstash/docs/blob/main/vector/api/get-started.mdx Example of a successful REST API response. The response contains a single 'result' field with the value 'Success'. ```json { "result": "Success" } ``` -------------------------------- ### Create a Workflow Endpoint in TanStack Start Source: https://github.com/upstash/docs/blob/main/workflow/quickstarts/tanstack-start.mdx Defines an API route at /api/workflow using Upstash Workflow's serve() function. The workflow processes a request payload through two sequential steps, each calling someWork to transform the input. Requires a TanStack Start project with @upstash/workflow/tanstack installed. ```typescript import { createFileRoute } from '@tanstack/react-router' import { serve } from '@upstash/workflow/tanstack' const someWork = (input: string) => { return `processed '${JSON.stringify(input)}'` } export const Route = createFileRoute('/api/workflow')({ server: { handlers: serve<string>(async (context) => { const input = context.requestPayload const result1 = await context.run('step1', () => { const output = someWork(input) console.log('step 1 input', input, 'output', output) return output }) await context.run('step2', () => { const output = someWork(result1) console.log('step 2 input', result1, 'output', output) }) }), }, }) ``` -------------------------------- ### go-redis example Source: https://github.com/upstash/docs/blob/main/redis/commands/json/json-objlen.mdx Example using the go-redis client. It parses the REDIS_URL environment variable, creates a client, and calls JSONObjLen with a context and path. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.JSONObjLen(context.Background(), "profile", "$").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Connect to Upstash Redis with redis-cli and run commands Source: https://github.com/upstash/docs/blob/main/redis/overall/getstarted.mdx Use the redis-cli command copied from the Upstash Console Details tab to connect to your database. The token is the database password. The example shows setting, getting, and incrementing a counter, with responses displayed. ```bash > redis-cli --tls -a YOUR_TOKEN -h YOUR_ENDPOINT -p YOUR_PORT YOUR_ENDPOINT:YOUR_PORT> set counter 0 OK YOUR_ENDPOINT:YOUR_PORT> get counter "0" YOUR_ENDPOINT:YOUR_PORT> incr counter (int) 1 YOUR_ENDPOINT:YOUR_PORT> incr counter (int) 2 ``` -------------------------------- ### Redis CLI example Source: https://github.com/upstash/docs/blob/main/redis/commands/streams/xpending.mdx Runs XPENDING with a key and group to get a summary of pending messages. ```bash XPENDING my-key workers ``` -------------------------------- ### Invoke startBackgroundJob on button click (src/app/page.tsx) Source: https://github.com/upstash/docs/blob/main/qstash/quickstarts/vercel-nextjs.mdx Updated client component that imports the server action and calls it in the click handler. ```tsx "use client" import { startBackgroundJob } from "@/app/actions" export default function Home() { async function handleClick() { await startBackgroundJob() } return ( <main className="flex h-lvh items-center justify-center"> <button onClick={handleClick} className="btn btn-primary w-1/2 h-56 bg-green-500 text-xl sm:text-3xl rounded-lg hover:bg-green-600" > Start Background Job </button> </main> ) } ``` -------------------------------- ### Example command to run in Hermes Source: https://github.com/upstash/docs/blob/main/box/guides/hermes-plugin-setup.mdx Ask Hermes to run uname -a and whoami. The output comes from the box with the user boxuser, and commands start in /home/boxuser. ```text Run uname -a and whoami. ``` -------------------------------- ### Error response JSON Source: https://github.com/upstash/docs/blob/main/vector/api/get-started.mdx Example of an error response from the REST API. Contains an 'error' field with the error message and a 'status' field with the HTTP status code. ```json { "error": "Unauthorized: Invalid auth token", "status": 401 } ``` -------------------------------- ### Run Django development server Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/django.mdx Start the Django development server to test the application. ```shell python manage.py runserver ``` -------------------------------- ### go-redis example Source: https://github.com/upstash/docs/blob/main/redis/commands/list/lmpop.mdx Example using the go-redis SDK. It parses the REDIS_URL environment variable, creates a client, and calls LMPop with direction LEFT, count 0, and the key. The result is printed. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) _, result, err := client.LMPop(context.Background(), "LEFT", 0, "my-key").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### get usage example Source: https://github.com/upstash/docs/blob/main/blob/sdks/py/bucket.mdx Example of using get to retrieve an object and access its properties. Unlike the TypeScript SDK, get reads the whole body into memory before returning. ```python res = bucket.get("reports/2026-01.pdf") res.content_type # 'application/pdf' res.size # 184302 res.etag # '"9f3c..."' res.metadata # {'owner': 'u7'} res.content # bytes, the whole object ``` -------------------------------- ### Initialize Go project Source: https://github.com/upstash/docs/blob/main/qstash/quickstarts/fly-io/go.mdx Creates a new folder and initializes a Go module for the Fly.io deployment. ```bash mkdir flyio-go cd flyio-go go mod init flyio-go ``` -------------------------------- ### go-redis HTTL Example Source: https://github.com/upstash/docs/blob/main/redis/commands/hash/httl.mdx Go example using go-redis. Parses REDIS_URL, creates a client, and calls HTTL with key, count, and field. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.HTTL(context.Background(), "my-key", "1", "field").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Create project and install Express and ioredis Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/express.mdx Commands to create a project directory, initialize npm, install express and ioredis, and set the start script to run index.js. ```shell mkdir express-upstash && cd express-upstash npm init -y npm install express ioredis npm pkg set scripts.start="node index.js" ``` -------------------------------- ### go-redis example Source: https://github.com/upstash/docs/blob/main/redis/commands/streams/xpending.mdx Uses the go-redis client to call XPending with a key and group, then prints the result. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.XPending(context.Background(), "my-key", "workers").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Run the demo application locally Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/koyeb.mdx Starts the application server in debug mode. After running, navigate to 127.0.0.1:3000 to see the counter; it increments on each page refresh. Press CTRL-c to stop. ```bash npm run dev ``` -------------------------------- ### Create project directory Source: https://github.com/upstash/docs/blob/main/redis/tutorials/aws_app_runner_with_redis.mdx Commands to create and enter the project directory for the App Runner example. ```bash mkdir app_runner_example cd app_runner_example ``` -------------------------------- ### Upload a file from the browser (React) Source: https://github.com/upstash/docs/blob/main/blob/overall/quickstart.mdx Client component that uses useUpload to start an upload, show progress, and display the result. The accept attribute comes from the route's GET, so oversized files are refused before any request. ```TSX // app/page.tsx "use client" import { useUpload } from "@/lib/upload-hooks" export default function Page() { const { start, upload, accept } = useUpload() return ( <div> <input type="file" accept={accept} onChange={(e) => start({ file: e.target.files?.[0] })} /> {upload && <p>{upload.status}</p>} {upload?.pending && <progress value={upload.percent} max={100} />} {upload?.status === "done" && ( <a href={upload.blob.url}>{upload.blob.path}</a> )} {upload?.status === "error" && <p>{upload.error.message}</p>} </div> ) } ``` -------------------------------- ### Run the Flask app Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/flask.mdx Start the Flask development server locally. ```shell python app.py ``` -------------------------------- ### Get usage example Source: https://github.com/upstash/docs/blob/main/blob/sdks/go/bucket.mdx Example of calling Get to download a blob. The Body is a stream that must be closed; a missing object fails with not_found. ```go res, err := bucket.Get(ctx, "reports/2026-01.pdf") if err != nil { return err } defer res.Body.Close() res.ContentType // "application/pdf" res.Size // 184302 res.ETag // "\"9f3c...\"" res.Metadata // map[owner:u7] io.Copy(w, res.Body) ``` -------------------------------- ### Upsert Vector with Metadata Source: https://github.com/upstash/docs/blob/main/vector/sdks/py/gettingstarted.mdx Example of upserting a random vector with metadata into the Upstash Vector index. Initializes the client from environment variables and recommends reusing the client outside the request handler in serverless environments. ```python import random from upstash_vector import Index # Initialize the index client using environment variables index = Index.from_env() def main(): # Define the dimension based on the index configuration dimension = 128 # Generate a random vector for upsert vector_to_upsert = [random.random() for _ in range(dimension)] # Additional metadata associated with the vector metadata = {"text": "example test for metadata"} # Upsert the vector into the index index.upsert(vectors=[ ("id-for-vector", vector_to_upsert, metadata) ]) ``` -------------------------------- ### Create Django project and app Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/django.mdx Create a new Django project and start a new app within it. ```shell django-admin startproject myproject cd myproject python manage.py startapp myapp ``` -------------------------------- ### GET example with upstash_redis Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Uses Redis.from_env() to create a client and get the value of 'my-key'. ```python from upstash_redis import Redis redis = Redis.from_env() result = redis.get("my-key") print(result) ``` -------------------------------- ### Start QStash dev server with CLI Source: https://github.com/upstash/docs/blob/main/workflow/howto/local-development/development-server.mdx Run this command to start the QStash development server manually. The CLI will output environment variables and a sample cURL request. ```javascript npx @upstash/qstash-cli dev ``` -------------------------------- ### PTTL Example with redis-rs Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the redis-rs client for Rust. Uses the REDIS_URL environment variable and connection.pttl() to get the TTL in milliseconds. ```rust use redis::TypedCommands; fn main() -> redis::RedisResult<()> { let url = std::env::var("REDIS_URL").expect("REDIS_URL is not set"); let client = redis::Client::open(url)?; let mut connection = client.get_connection()?; let result = connection.pttl("my-key")?; println!("{result:?}"); Ok(()) } ``` -------------------------------- ### Deploy to Koyeb via CLI Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/koyeb.mdx Initializes a Koyeb app with the specified Git repository, port 3000, and environment variables. Replace the placeholders with your GitHub username, repository name, and Upstash Redis credentials. ```bash koyeb app init example-koyeb-upstash \ --git github.com/<YOUR_GITHUB_USERNAME>/<YOUR_REPOSITORY_NAME> \ --git-branch main \ --ports 3000:http \ --routes /:3000 \ --env PORT=3000 \ --env UPSTASH_REDIS_REST_URL="<YOUR_UPSTASH_REDIS_REST_URL>" \ --env UPSTASH_REDIS_REST_TOKEN="<YOUR_UPSTASH_REDIS_REST_TOKEN>" ``` -------------------------------- ### PTTL Example with jedis Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the jedis client for Java. Uses the REDIS_URL environment variable and jedis.pttl() to get the TTL in milliseconds. ```java import java.net.URI; import redis.clients.jedis.Jedis; try (Jedis jedis = new Jedis(new URI(System.getenv("REDIS_URL")))) { Object result = jedis.pttl("my-key"); System.out.println(result); } ``` -------------------------------- ### PTTL Example with go-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the go-redis client for Go. Uses the REDIS_URL environment variable and client.PTTL() to get the TTL in milliseconds. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.PTTL(context.Background(), "my-key").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### go-redis SINTERSTORE Example Source: https://github.com/upstash/docs/blob/main/redis/commands/set/sinterstore.mdx Example using the go-redis client. It parses the REDIS_URL, creates a client, calls SInterStore, and prints the result. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.SInterStore(context.Background(), "destination-key", "my-key").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Open plain proxy for local development Source: https://github.com/upstash/docs/blob/main/redis/quickstarts/fly.mdx Starts a plain proxy for local application use. Keep it running and point your app at localhost:16379 with the password from your Redis URL. ```shell fly redis proxy ``` -------------------------------- ### PTTL Example with redis-py Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the redis-py client for Python. Uses the REDIS_URL environment variable and client.pttl() to get the TTL in milliseconds. ```python import os import redis client = redis.from_url(os.environ["REDIS_URL"]) result = client.pttl("my-key") print(result) ``` -------------------------------- ### PTTL Example with node-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the node-redis client for Node.js. Uses the REDIS_URL environment variable and client.pTTL() to get the TTL in milliseconds. ```ts import { createClient } from "redis"; const client = await createClient({ url: process.env.REDIS_URL }) .on("error", console.error) .connect(); const result = await client.pTTL("my-key"); console.log(result); ``` -------------------------------- ### Create a Box with initCommand (TypeScript) Source: https://github.com/upstash/docs/blob/main/box/overall/quickstart.mdx Create a Box that runs a startup script (initCommand) each time the box starts. The command runs from /workspace/home. ```typescript const box = await Box.create({ runtime: "node", initCommand: `node -e 'require("http").createServer((_, res) => res.end("Hello from Box!")).listen(3000)'`, }) ``` -------------------------------- ### PTTL Example with ioredis Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the ioredis client for Node.js. Uses the REDIS_URL environment variable and redis.pttl() to get the TTL in milliseconds. ```ts import Redis from "ioredis"; const redis = new Redis(process.env.REDIS_URL!); const result = await redis.pttl("my-key"); console.log(result); ``` -------------------------------- ### SDIFFSTORE Example with go-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/set/sdiffstore.mdx Example using the go-redis Go client. It parses REDIS_URL, creates a client, and calls SDiffStore to store the difference, printing the result. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.SDiffStore(context.Background(), "destination-key", "my-key").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### PTTL Example with upstash_redis Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the upstash_redis client for Python. Uses Redis.from_env() to create a client and redis.pttl() to get the TTL in milliseconds. ```python from upstash_redis import Redis redis = Redis.from_env() result = redis.pttl("my-key") print(result) ``` -------------------------------- ### go-redis Example Source: https://github.com/upstash/docs/blob/main/redis/commands/json/json-nummultby.mdx Example using the go-redis client. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.Do(context.Background(), "JSON.NUMMULTBY", "profile", "$.score", "2").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### PTTL Example with @upstash/redis Source: https://github.com/upstash/docs/blob/main/redis/commands/generic/pttl.mdx Example of using PTTL with the @upstash/redis client for Node.js. Uses Redis.fromEnv() to create a client and redis.pttl() to get the TTL in milliseconds. ```ts import { Redis } from "@upstash/redis"; const redis = Redis.fromEnv(); const millis = await redis.pttl("key"); ``` -------------------------------- ### HELLO command syntax Source: https://github.com/upstash/docs/blob/main/redis/commands/connection/hello.mdx Shows the HELLO command syntax with optional protover, AUTH, and SETNAME arguments. Use it to switch the connection to RESP2 or RESP3 and optionally authenticate and name the connection in one round trip. ```redis HELLO [<protover> [AUTH <username> <password>] [SETNAME <clientname>]] ``` -------------------------------- ### Install upstash-pulumi Go SDK with go get Source: https://github.com/upstash/docs/blob/main/devops/pulumi/overview.mdx Install the Upstash Pulumi provider for Go using go get to grab the latest version of the library. ```bash go get github.com/upstash/pulumi-upstash/sdk/go/... ``` -------------------------------- ### go-redis LINSERT example Source: https://github.com/upstash/docs/blob/main/redis/commands/list/linsert.mdx Example using the go-redis client. Parses REDIS_URL, creates a client, inserts 'element' before 'pivot' in 'my-key', and prints the result. ```go package main import ( "context" "fmt" "os" "github.com/redis/go-redis/v9" ) func main() { opts, err := redis.ParseURL(os.Getenv("REDIS_URL")) if err != nil { panic(err) } client := redis.NewClient(opts) result, err := client.LInsertBefore(context.Background(), "my-key", "pivot", "element").Result() if err != nil { panic(err) } fmt.Println(result) } ``` -------------------------------- ### Redis CLI examples for $boost Source: https://github.com/upstash/docs/blob/main/redis/search/query-operators/boolean-operators/boost.mdx Two Redis CLI SEARCH.QUERY commands: one boosts wireless and in-stock items, another demotes budget items with a negative boost. ```bash # Prioritize wireless and in-stock items SEARCH.QUERY products '{"$must": {"name": "headphones"}, "$should": {"description": "wireless", "inStock": true, "$boost": 5.0}}' # Demote budget items without excluding them SEARCH.QUERY products '{"$must": {"category": "electronics"}, "$should": {"description": "budget", "$boost": -1.0}}' ``` -------------------------------- ### Add Data in Python Source: https://github.com/upstash/docs/blob/main/redis/search/getting-started.mdx Sets two JSON documents under keys 'product:1' and 'product:2' and waits for indexing. Writes are indexed asynchronously. ```Python redis.json.set("product:1", "$", { "name": "Wireless Headphones", "description": "Premium noise-cancelling wireless headphones with 30-hour battery life", "category": "electronics", "price": 199.99, "inStock": True, }) redis.json.set("product:2", "$", { "name": "Running Shoes", "description": "Lightweight running shoes with advanced cushioning technology", "category": "sports", "price": 129.99, "inStock": True, }) index.wait_indexing() ``` -------------------------------- ### GET example with node-redis Source: https://github.com/upstash/docs/blob/main/redis/commands/string/get.mdx Creates a Redis client with error handling and gets the value of 'my-key'. ```ts import { createClient } from "redis"; const client = await createClient({ url: process.env.REDIS_URL }) .on("error", console.error) .connect(); const result = await client.get("my-key"); console.log(result); ``` -------------------------------- ### Create your own endpoint (src/app/api/long-task/route.ts) Source: https://github.com/upstash/docs/blob/main/qstash/quickstarts/vercel-nextjs.mdx POST endpoint that sends 10 requests with 500ms delay. Be mindful of Vercel's serverless function time limits. ```ts export async function POST(request: Request) { const data = await request.json() for (let i = 0; i < 10; i++) { await fetch("https://firstqstashmessage.requestcatcher.com/test", { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }) await new Promise((resolve) => setTimeout(resolve, 500)) } return Response.json({ success: true }) } ``` -------------------------------- ### Run setup script Source: https://github.com/upstash/docs/blob/main/box/guides/claude-managed-agents.mdx Executes the setup.ts script with environment variables loaded from .env. ```bash npx tsx --env-file=.env setup.ts ``` -------------------------------- ### Send Welcome Email (Python) Source: https://github.com/upstash/docs/blob/main/workflow/examples/authWebhook.mdx Sends a welcome email with a 14-day free trial message using context.run. ```python async def _send_welcome_email() -> None: await send_email( email, "Welcome to our platform!, You have 14 days of free trial." ) await context.run("send welcome email", _send_welcome_email) ```