diff --git a/docs.json b/docs.json index 720a78374..89c193482 100644 --- a/docs.json +++ b/docs.json @@ -95,19 +95,13 @@ ] }, { - "group": "Next.js 15", + "group": "Next.js 16", "pages": [ "redis/quickstarts/nextjs-app-router", "redis/quickstarts/nextjs-pages-router" ] }, - { - "group": "SST", - "pages": [ - "redis/quickstarts/sst-v2", - "redis/quickstarts/ion" - ] - }, + "redis/quickstarts/sst", { "group": "Python", "pages": [ @@ -1938,6 +1932,14 @@ ] }, "redirects": [ + { + "source": "/redis/quickstarts/ion", + "destination": "/redis/quickstarts/sst" + }, + { + "source": "/redis/quickstarts/sst-v2", + "destination": "/redis/quickstarts/sst" + }, { "source": "/workflow/basics/context", "destination": "/workflow/steps" diff --git a/img/redis-deno/connect.png b/img/redis-deno/connect.png new file mode 100644 index 000000000..95213df6e Binary files /dev/null and b/img/redis-deno/connect.png differ diff --git a/img/redis-deno/create.png b/img/redis-deno/create.png deleted file mode 100644 index f10c1ffeb..000000000 Binary files a/img/redis-deno/create.png and /dev/null differ diff --git a/img/redis-deno/deploy.png b/img/redis-deno/deploy.png deleted file mode 100644 index 9c64bc827..000000000 Binary files a/img/redis-deno/deploy.png and /dev/null differ diff --git a/img/redis-deno/env-variables.png b/img/redis-deno/env-variables.png new file mode 100644 index 000000000..a2d825d53 Binary files /dev/null and b/img/redis-deno/env-variables.png differ diff --git a/img/redis-deno/playground.png b/img/redis-deno/playground.png new file mode 100644 index 000000000..aac22182e Binary files /dev/null and b/img/redis-deno/playground.png differ diff --git a/img/redis-gcloud/basics.png b/img/redis-gcloud/basics.png deleted file mode 100644 index e17064120..000000000 Binary files a/img/redis-gcloud/basics.png and /dev/null differ diff --git a/img/redis-gcloud/create-service.png b/img/redis-gcloud/create-service.png new file mode 100644 index 000000000..01245288b Binary files /dev/null and b/img/redis-gcloud/create-service.png differ diff --git a/img/redis-gcloud/entry-point.png b/img/redis-gcloud/entry-point.png new file mode 100644 index 000000000..db91649fc Binary files /dev/null and b/img/redis-gcloud/entry-point.png differ diff --git a/img/redis-gcloud/env-variables.png b/img/redis-gcloud/env-variables.png new file mode 100644 index 000000000..7de48005e Binary files /dev/null and b/img/redis-gcloud/env-variables.png differ diff --git a/img/redis-gcloud/environment.png b/img/redis-gcloud/environment.png deleted file mode 100644 index 3cf3db90b..000000000 Binary files a/img/redis-gcloud/environment.png and /dev/null differ diff --git a/llms-full.txt b/llms-full.txt index 392c05404..943c63486 100644 --- a/llms-full.txt +++ b/llms-full.txt @@ -17113,7 +17113,7 @@ customize the eviction behavior according to their specific needs. Source: https://upstash.com/docs/redis/features/globaldatabase - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. In the global database, the replicas are distributed across multiple regions @@ -17491,7 +17491,7 @@ Source: https://upstash.com/docs/redis/features/restapi database](/docs/redis/overall/getstarted), then [find your credentials](/docs/redis/howto/connect-client) in the console. - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. In the [Upstash Console](https://console.upstash.com/redis), select your database. Then, in the database page, you will see the section that includes the endpoint URL and token details. When you hover over the `Endpoint` or `Token / Readonly Token` fields, copy button will appear for each. You can click it to easily copy the values you need for your connection. @@ -18664,7 +18664,7 @@ Because it is already covered in [Getting Started](../overall/getstarted), we will skip it here. - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. ## Database @@ -18837,7 +18837,7 @@ See supported. - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. ## Quick Start @@ -21869,7 +21869,7 @@ Upstash Redis is a **highly available, infinitely scalable** Redis-compatible da * Optional SOC-2 compliance, encryption at rest and much more - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. *** @@ -22067,15 +22067,14 @@ We believe that Upstash is the best storage for your Lambda Functions because: - [Fastly](https://upstash.com/docs/redis/quickstarts/fastlycompute.md) - [Flask](https://upstash.com/docs/redis/quickstarts/flask.md) - [Fly.io](https://upstash.com/docs/redis/quickstarts/fly.md) -- [Google Cloud Functions](https://upstash.com/docs/redis/quickstarts/google-cloud-functions.md) -- [Ion](https://upstash.com/docs/redis/quickstarts/ion.md) +- [Google Cloud Run functions](https://upstash.com/docs/redis/quickstarts/google-cloud-functions.md) - [ioredis note](https://upstash.com/docs/redis/quickstarts/ioredisnote.md) - [Koyeb](https://upstash.com/docs/redis/quickstarts/koyeb.md) - [Laravel](https://upstash.com/docs/redis/quickstarts/laravel.md) - [App Router](https://upstash.com/docs/redis/quickstarts/nextjs-app-router.md) - [Pages Router](https://upstash.com/docs/redis/quickstarts/nextjs-pages-router.md) -- [ AWS Lambda](https://upstash.com/docs/redis/quickstarts/python-aws-lambda.md) -- [SST v2](https://upstash.com/docs/redis/quickstarts/sst-v2.md) +- [AWS Lambda](https://upstash.com/docs/redis/quickstarts/python-aws-lambda.md) +- [SST](https://upstash.com/docs/redis/quickstarts/sst.md) - [Supabase Functions](https://upstash.com/docs/redis/quickstarts/supabase.md) - [App Router](https://upstash.com/docs/redis/quickstarts/vercel-functions-app-router.md) - [Pages Router](https://upstash.com/docs/redis/quickstarts/vercel-functions-pages-router.md) @@ -22775,7 +22774,41 @@ export default agentkit({ chatHistory: true }); Both tools take `userId` from the session, so the model cannot widen a lookup past the current user's own transcripts. - +Your own code reads the same store with `ChatHistory` from `@upstash/agentkit-sdk`, which is how you'd +build a history sidebar or run evals over past sessions: + +```bash +npm install @upstash/agentkit-sdk @upstash/redis +``` + +```ts +// app/api/chats/route.ts — server-side only; `userId` comes from your session, never the client +import { Redis } from "@upstash/redis"; +import { ChatHistory } from "@upstash/agentkit-sdk"; + +// `ChatHistory` is generic over the message type, and the extension doesn't export the shape its +// hook writes — declare it to get a typed `messages` array back. +type StoredMessage = { role: "user" | "assistant"; content: string; createdAt: number }; + +// Pass the same prefix / indexName / ttlSeconds you set on `chatHistory` in the mount file. +const history = new ChatHistory({ redis: Redis.fromEnv() }); + +// List: summaries only (no messages), newest-updated first. +const chats = await history.listChats({ userId, limit: 50 }); + +// Search: `$smart` fuzzy match, summaries plus a BM25 `score`. target: "user" | "model" | "both". +const hits = await history.searchChats({ userId, query: "the retry schema", target: "both", limit: 20 }); + +// Read: one full transcript, or null if this user has no chat with that sessionId. +const chat = await history.getChat({ userId, sessionId: hits[0].sessionId }); +chat?.messages.forEach((m) => console.log(m.role, m.content)); +``` + +`userId` must be the same value the extension resolved for those sessions, and both ids are Redis key +parts, so `:` in a derived value is replaced with `_`. `deleteChat({ userId, sessionId })` removes a +chat and its index entry. + + Pass an object in place of `true` to tune storage: * `chatHistory.prefix` — base key prefix (default `agentkit:chat`). @@ -22787,10 +22820,7 @@ own transcripts. plus `$smart`-indexed user and model text. A search returns summaries, and a read is capped at 50 messages per call with a `truncated` flag, so neither can flood the context window. - Your own code can read the same store with `ChatHistory` from `@upstash/agentkit-sdk` - (`listChats` / `searchChats` / `getChat`), which is how you'd build a history sidebar or run evals - over past sessions. Redis is the durable record here, since Eve's own workflow store is pruned after - a run completes. + Redis is the durable record here, since Eve's own workflow store is pruned after a run completes. These tools look history up on demand. They don't resume a session: Eve does that through its own session cursor. @@ -23110,8 +23140,9 @@ export default defineSearchTools({ and `count_books.ts`. The index is created on first use, and every returned tool is already `defineTool`-branded. - This package has no chat history. It comes from the extension, or from `ChatHistory` in - `@upstash/agentkit-sdk` if you're writing the code yourself. + This package has no chat history. It comes from the extension, or from + [`ChatHistory` in `@upstash/agentkit-sdk`](#how-to-add-searchable-chat-history-to-vercel-eve) if + you're writing the code yourself. ## Working with Eve's `agent/` files @@ -23262,7 +23293,41 @@ export default agentkit({ chatHistory: true }); Both tools take `userId` from the session, so the model cannot widen a lookup past the current user's own transcripts. - +Your own code reads the same store with `ChatHistory` from `@upstash/agentkit-sdk`, which is how you'd +build a history sidebar or run evals over past sessions: + +```bash +npm install @upstash/agentkit-sdk @upstash/redis +``` + +```ts +// app/api/chats/route.ts — server-side only; `userId` comes from your session, never the client +import { Redis } from "@upstash/redis"; +import { ChatHistory } from "@upstash/agentkit-sdk"; + +// `ChatHistory` is generic over the message type, and the extension doesn't export the shape its +// hook writes — declare it to get a typed `messages` array back. +type StoredMessage = { role: "user" | "assistant"; content: string; createdAt: number }; + +// Pass the same prefix / indexName / ttlSeconds you set on `chatHistory` in the mount file. +const history = new ChatHistory({ redis: Redis.fromEnv() }); + +// List: summaries only (no messages), newest-updated first. +const chats = await history.listChats({ userId, limit: 50 }); + +// Search: `$smart` fuzzy match, summaries plus a BM25 `score`. target: "user" | "model" | "both". +const hits = await history.searchChats({ userId, query: "the retry schema", target: "both", limit: 20 }); + +// Read: one full transcript, or null if this user has no chat with that sessionId. +const chat = await history.getChat({ userId, sessionId: hits[0].sessionId }); +chat?.messages.forEach((m) => console.log(m.role, m.content)); +``` + +`userId` must be the same value the extension resolved for those sessions, and both ids are Redis key +parts, so `:` in a derived value is replaced with `_`. `deleteChat({ userId, sessionId })` removes a +chat and its index entry. + + Pass an object in place of `true` to tune storage: * `chatHistory.prefix` — base key prefix (default `agentkit:chat`). @@ -23274,10 +23339,7 @@ own transcripts. plus `$smart`-indexed user and model text. A search returns summaries, and a read is capped at 50 messages per call with a `truncated` flag, so neither can flood the context window. - Your own code can read the same store with `ChatHistory` from `@upstash/agentkit-sdk` - (`listChats` / `searchChats` / `getChat`), which is how you'd build a history sidebar or run evals - over past sessions. Redis is the durable record here, since Eve's own workflow store is pruned after - a run completes. + Redis is the durable record here, since Eve's own workflow store is pruned after a run completes. These tools look history up on demand. They don't resume a session: Eve does that through its own session cursor. @@ -23597,8 +23659,9 @@ export default defineSearchTools({ and `count_books.ts`. The index is created on first use, and every returned tool is already `defineTool`-branded. - This package has no chat history. It comes from the extension, or from `ChatHistory` in - `@upstash/agentkit-sdk` if you're writing the code yourself. + This package has no chat history. It comes from the extension, or from + [`ChatHistory` in `@upstash/agentkit-sdk`](#how-to-add-searchable-chat-history-to-vercel-eve) if + you're writing the code yourself. ## Working with Eve's `agent/` files @@ -24031,7 +24094,7 @@ redis = Redis( Source: https://upstash.com/docs/redis/sdks/py/gettingstarted - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. ## Install @@ -26442,7 +26505,7 @@ and for his continued efforts to keep it up to date with Upstash. Source: https://upstash.com/docs/redis/sdks/ts/getstarted - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. `@upstash/redis` is written in Deno and can be imported from @@ -33318,7 +33381,7 @@ from the list of the associated group and consumer. - [Serverless API with Java and Redis](https://upstash.com/docs/redis/tutorials/serverless_java_redis.md) - [TanStack AI Chat Persistance](https://upstash.com/docs/redis/tutorials/tanstack_chat_persistence.md): Use Upstash Redis to persist TanStack AI chat histories across reloads, navigation, and devices with a simple adapter. - [Using AWS SAM](https://upstash.com/docs/redis/tutorials/using_aws_sam.md) -- [Serverless Redis on Google Cloud Functions](https://upstash.com/docs/redis/tutorials/using_google_cloud_functions.md) +- [Serverless Redis on Google Cloud Run functions](https://upstash.com/docs/redis/tutorials/using_google_cloud_functions.md) - [Using Serverless Framework](https://upstash.com/docs/redis/tutorials/using_serverless_framework.md) # Advanced Settings diff --git a/llms.txt b/llms.txt index fd206f366..740b62dc4 100644 --- a/llms.txt +++ b/llms.txt @@ -352,15 +352,14 @@ - [Fastly](https://upstash.com/docs/redis/quickstarts/fastlycompute.md) - [Flask](https://upstash.com/docs/redis/quickstarts/flask.md) - [Fly.io](https://upstash.com/docs/redis/quickstarts/fly.md) -- [Google Cloud Functions](https://upstash.com/docs/redis/quickstarts/google-cloud-functions.md) -- [Ion](https://upstash.com/docs/redis/quickstarts/ion.md) +- [Google Cloud Run functions](https://upstash.com/docs/redis/quickstarts/google-cloud-functions.md) - [ioredis note](https://upstash.com/docs/redis/quickstarts/ioredisnote.md) - [Koyeb](https://upstash.com/docs/redis/quickstarts/koyeb.md) - [Laravel](https://upstash.com/docs/redis/quickstarts/laravel.md) - [App Router](https://upstash.com/docs/redis/quickstarts/nextjs-app-router.md) - [Pages Router](https://upstash.com/docs/redis/quickstarts/nextjs-pages-router.md) -- [ AWS Lambda](https://upstash.com/docs/redis/quickstarts/python-aws-lambda.md) -- [SST v2](https://upstash.com/docs/redis/quickstarts/sst-v2.md) +- [AWS Lambda](https://upstash.com/docs/redis/quickstarts/python-aws-lambda.md) +- [SST](https://upstash.com/docs/redis/quickstarts/sst.md) - [Supabase Functions](https://upstash.com/docs/redis/quickstarts/supabase.md) - [App Router](https://upstash.com/docs/redis/quickstarts/vercel-functions-app-router.md) - [Pages Router](https://upstash.com/docs/redis/quickstarts/vercel-functions-pages-router.md) @@ -850,7 +849,7 @@ - [Serverless API with Java and Redis](https://upstash.com/docs/redis/tutorials/serverless_java_redis.md) - [TanStack AI Chat Persistance](https://upstash.com/docs/redis/tutorials/tanstack_chat_persistence.md): Use Upstash Redis to persist TanStack AI chat histories across reloads, navigation, and devices with a simple adapter. - [Using AWS SAM](https://upstash.com/docs/redis/tutorials/using_aws_sam.md) -- [Serverless Redis on Google Cloud Functions](https://upstash.com/docs/redis/tutorials/using_google_cloud_functions.md) +- [Serverless Redis on Google Cloud Run functions](https://upstash.com/docs/redis/tutorials/using_google_cloud_functions.md) - [Using Serverless Framework](https://upstash.com/docs/redis/tutorials/using_serverless_framework.md) - [Advanced Settings](https://upstash.com/docs/search/features/advanced-settings.md) - [Algorithm](https://upstash.com/docs/search/features/algorithm.md) diff --git a/redis/features/globaldatabase.mdx b/redis/features/globaldatabase.mdx index 1e3d5ce32..24e813284 100644 --- a/redis/features/globaldatabase.mdx +++ b/redis/features/globaldatabase.mdx @@ -3,7 +3,7 @@ title: Global Database --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. diff --git a/redis/features/restapi.mdx b/redis/features/restapi.mdx index 111c95f28..f151f1af3 100644 --- a/redis/features/restapi.mdx +++ b/redis/features/restapi.mdx @@ -10,7 +10,7 @@ description: Access your Upstash Redis database over HTTP, from serverless and e database](/redis/overall/getstarted), then [find your credentials](/redis/howto/connect-client) in the console. - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. In the [Upstash Console](https://console.upstash.com/redis), select your database. Then, in the database page, you will see the section that includes the endpoint URL and token details. When you hover over the `Endpoint` or `Token / Readonly Token` fields, copy button will appear for each. You can click it to easily copy the values you need for your connection. diff --git a/redis/howto/connect-client.mdx b/redis/howto/connect-client.mdx index 1ad742860..afca5cdb3 100755 --- a/redis/howto/connect-client.mdx +++ b/redis/howto/connect-client.mdx @@ -11,7 +11,7 @@ Because it is already covered in [Getting Started](../overall/getstarted), we will skip it here. - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. ## Database diff --git a/redis/howto/connect-with-upstash-redis.mdx b/redis/howto/connect-with-upstash-redis.mdx index dbb387486..e0712cb34 100755 --- a/redis/howto/connect-with-upstash-redis.mdx +++ b/redis/howto/connect-with-upstash-redis.mdx @@ -24,7 +24,7 @@ See supported. - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. diff --git a/redis/overall/getstarted.mdx b/redis/overall/getstarted.mdx index ac9460b50..2ad59f34f 100755 --- a/redis/overall/getstarted.mdx +++ b/redis/overall/getstarted.mdx @@ -16,7 +16,7 @@ Upstash Redis is a **highly available, infinitely scalable** Redis-compatible da - Optional SOC-2 compliance, encryption at rest and much more - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. diff --git a/redis/quickstarts/aws-lambda.mdx b/redis/quickstarts/aws-lambda.mdx index e437fe719..1f27e884f 100644 --- a/redis/quickstarts/aws-lambda.mdx +++ b/redis/quickstarts/aws-lambda.mdx @@ -3,7 +3,7 @@ title: "AWS Lambda" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -13,7 +13,7 @@ title: "AWS Lambda" ### Prerequisites -- Complete all steps in [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html) +- Complete all steps in [Getting started with the AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/getting-started.html) ### Project Setup @@ -70,14 +70,14 @@ export class CounterCdkStack extends cdk.Stack { const counterFunction = new nodejs.NodejsFunction(this, 'CounterFunction', { entry: 'api/counter.ts', handler: 'handler', - runtime: lambda.Runtime.NODEJS_20_X, + runtime: lambda.Runtime.NODEJS_24_X, environment: { UPSTASH_REDIS_REST_URL: process.env.UPSTASH_REDIS_REST_URL || '', UPSTASH_REDIS_REST_TOKEN: process.env.UPSTASH_REDIS_REST_TOKEN || '', }, bundling: { format: nodejs.OutputFormat.ESM, - target: "node20", + target: "node24", nodeModules: ['@upstash/redis'], }, }); diff --git a/redis/quickstarts/azure-functions.mdx b/redis/quickstarts/azure-functions.mdx index 635874fe5..37d349575 100644 --- a/redis/quickstarts/azure-functions.mdx +++ b/redis/quickstarts/azure-functions.mdx @@ -3,7 +3,7 @@ title: "Azure Functions" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -15,14 +15,14 @@ title: "Azure Functions" 1. [Create an Azure account.](https://azure.microsoft.com/en-us/free/) 2. [Set up Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) -3. [Install the Azure Functions Core Tools](https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-typescript) +3. [Install the Azure Functions Core Tools](https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools) ### Project Setup Initialize the project: ```shell -func init --typescript +func init --worker-runtime node --language typescript ``` Install `@upstash/redis` @@ -65,10 +65,10 @@ app.http('CounterFunction', { ### Create Azure Resources -You can use the command below to find the `name` of a region near you. +You can use the command below to find the `name` of a region near you that supports the Flex Consumption plan. ```shell -az account list-locations +az functionapp list-flexconsumption-locations ``` Create a resource group. @@ -83,10 +83,10 @@ Create a storage account. az storage account create --name --location --resource-group AzureFunctionsQuickstart-rg --sku Standard_LRS --allow-blob-public-access false ``` -Create your Function App. +Create your Function App on the Flex Consumption plan. ```shell -az functionapp create --resource-group AzureFunctionsQuickstart-rg --consumption-plan-location --runtime node --runtime-version 18 --functions-version 4 --name --storage-account +az functionapp create --resource-group AzureFunctionsQuickstart-rg --name --storage-account --flexconsumption-location --runtime node --runtime-version 22 ``` ### Database Setup diff --git a/redis/quickstarts/cloudflareworkers.mdx b/redis/quickstarts/cloudflareworkers.mdx index 3ec6f79b7..86e3dc768 100755 --- a/redis/quickstarts/cloudflareworkers.mdx +++ b/redis/quickstarts/cloudflareworkers.mdx @@ -3,7 +3,7 @@ title: "Cloudflare Workers" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -42,7 +42,7 @@ This will create a new Cloudflare Workers project: ───────────────────────────────────────────────────────────────────────────────────────────────── -👋 Welcome to create-cloudflare v2.50.8! +👋 Welcome to create-cloudflare vX.Y.Z! 🧡 Let's get started. 📊 Cloudflare collects telemetry about your usage of Create-Cloudflare. @@ -101,14 +101,12 @@ export interface Env { } export default { - async fetch(request, env, ctx): Promise { - const redis = Redis.fromEnv(env); - const count = await redis.incr("counter"); - return new Response(JSON.stringify({ count })); - - }, + async fetch(request, env, ctx): Promise { + const redis = Redis.fromEnv(env); + const count = await redis.incr("counter"); + return new Response(JSON.stringify({ count })); + }, } satisfies ExportedHandler; - ``` ```js src/index.js @@ -131,7 +129,20 @@ There are two methods for setting up the credentials for Redis. One for worker l #### Using Cloudflare Secrets (Worker Level Secrets) -This is the common way of creating secrets for your worker, see [Workflow Secrets](https://developers.cloudflare.com/workers/configuration/secrets/) +This is the common way of creating secrets for your worker, see [Workers Secrets](https://developers.cloudflare.com/workers/configuration/secrets/) + +The recommended method is the Wrangler CLI, since secrets added this way persist +across deployments. Navigate to [Upstash Console](https://console.upstash.com), +get your Redis credentials and run in your project directory: + +```shell +npx wrangler secret put UPSTASH_REDIS_REST_URL +npx wrangler secret put UPSTASH_REDIS_REST_TOKEN +``` + +Each command prompts you for the secret value. + +Alternatively, you can add the secrets from the dashboard: - Navigate to [Upstash Console](https://console.upstash.com) and get your Redis credentials. @@ -158,15 +169,14 @@ export interface Env { } export default { - async fetch(request, env, ctx): Promise { - const redis = Redis.fromEnv({ - UPSTASH_REDIS_REST_URL: await env.UPSTASH_REDIS_REST_URL.get(), - UPSTASH_REDIS_REST_TOKEN: await env.UPSTASH_REDIS_REST_TOKEN.get(), - }); - const count = await redis.incr("counter"); - return new Response(JSON.stringify({ count })); - - }, + async fetch(request, env, ctx): Promise { + const redis = Redis.fromEnv({ + UPSTASH_REDIS_REST_URL: await env.UPSTASH_REDIS_REST_URL.get(), + UPSTASH_REDIS_REST_TOKEN: await env.UPSTASH_REDIS_REST_TOKEN.get(), + }); + const count = await redis.incr("counter"); + return new Response(JSON.stringify({ count })); + }, } satisfies ExportedHandler; ``` @@ -204,8 +214,7 @@ Open a different terminal and test the endpoint. Note the destination url is the same that was printed in the previous deploy step. ```bash -curl -X POST 'https://..workers.dev' \ - -H 'Content-Type: application/json' +curl https://..workers.dev ``` The response will be in the format of `{"count":20}` @@ -215,12 +224,12 @@ In the logs you should see something like this: ```bash $ npx wrangler tail -⛅️ wrangler 4.43.0 +⛅️ wrangler X.Y.Z -------------------- -Successfully created tail, expires at 2025-10-16T18:59:18Z +Successfully created tail, expires at Connected to , waiting for logs... -POST https://..workers.dev/ - Ok @ 10/16/2025, 4:05:30 PM +GET https://..workers.dev/ - Ok @ ``` ## Repositories diff --git a/redis/quickstarts/deno-deploy.mdx b/redis/quickstarts/deno-deploy.mdx index e3a6339db..20728f154 100644 --- a/redis/quickstarts/deno-deploy.mdx +++ b/redis/quickstarts/deno-deploy.mdx @@ -3,50 +3,72 @@ title: "Deno Deploy" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. This is a step-by-step guide on how to use Upstash Redis to create a view -counter in your Deno deploy project. +counter in your Deno Deploy project. -### Create a database +### 1. Create a database Create a Redis database using [Upstash Console](https://console.upstash.com) or [Upstash CLI](https://github.com/upstash/cli). Select the global to minimize the latency from all edge locations. Copy the `UPSTASH_REDIS_REST_URL` and -`UPSTASH_REDIS_REST_TOKEN` for the next steps. +`UPSTASH_REDIS_REST_TOKEN` from the **Connect** section of your database for the +next steps. -### Create a Deno deploy project + + + -Go to [https://dash.deno.com/projects](https://dash.deno.com/projects) and -create a new playground project. +### 2. Create a Deno Deploy playground -![](/img/redis-deno/create.png) +Go to [https://console.deno.com](https://console.deno.com), open your +organization's **Applications** page and click **New Playground**. This creates +a "Hello World" playground with a browser editor. -### 2. Edit the handler function + + + -Then paste the following code into the browser editor: +### 3. Set the environment variables + +Click **Env Variables** in the top bar of the playground and add the +`UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` variables. You can add +them one by one with **Add variable**, or paste both lines you copied from the +Upstash Console into **Import from .env file** and click **Import Variables**. + + + + + +### 4. Edit the handler function + +Paste the following code into the browser editor: ```ts -import { serve } from "https://deno.land/std@0.142.0/http/server.ts"; -import { Redis } from "https://deno.land/x/upstash_redis@v1.14.0/mod.ts"; - -serve(async (_req: Request) => { - if (!_req.url.endsWith("favicon.ico")) { - const redis = new Redis({ - url: "UPSTASH_REDIS_REST_URL", - token: "UPSTASH_REDIS_REST_TOKEN", - }); - - const counter = await redis.incr("deno-counter"); - return new Response(JSON.stringify({ counter }), { status: 200 }); +import { Redis } from "npm:@upstash/redis"; + +const redis = new Redis({ + url: Deno.env.get("UPSTASH_REDIS_REST_URL")!, + token: Deno.env.get("UPSTASH_REDIS_REST_TOKEN")!, +}); + +Deno.serve(async (req: Request) => { + if (new URL(req.url).pathname === "/favicon.ico") { + return new Response(null, { status: 404 }); } + + const counter = await redis.incr("deno-counter"); + return new Response(JSON.stringify({ counter }), { + status: 200, + headers: { "Content-Type": "application/json" }, + }); }); ``` -### 3. Deploy and Run - -Simply click on `Save & Deploy` at the top of the screen. +### 5. Deploy and run -![](/img/redis-deno/deploy.png) +Click **Deploy** in the top bar. Once the build finishes, open the playground +URL to see the counter increase on every refresh. diff --git a/redis/quickstarts/digitalocean.mdx b/redis/quickstarts/digitalocean.mdx index d785fdc49..b6a810b6b 100755 --- a/redis/quickstarts/digitalocean.mdx +++ b/redis/quickstarts/digitalocean.mdx @@ -3,7 +3,7 @@ title: "DigitalOcean" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. diff --git a/redis/quickstarts/django.mdx b/redis/quickstarts/django.mdx index 46bed713d..16a9ca206 100644 --- a/redis/quickstarts/django.mdx +++ b/redis/quickstarts/django.mdx @@ -3,7 +3,7 @@ title: "Django" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. diff --git a/redis/quickstarts/elixir.mdx b/redis/quickstarts/elixir.mdx index 38d66aa3b..df0f0f38f 100644 --- a/redis/quickstarts/elixir.mdx +++ b/redis/quickstarts/elixir.mdx @@ -4,7 +4,7 @@ description: "Tutorial on Using Upstash Redis In Your Phoenix App and Deploying --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -44,7 +44,7 @@ add the following two entries to the dependencies in the `mix.exs` file ```elixir defp deps do [ - {:redix, "~> 1.1"}, + {:redix, "~> 1.5"}, {:castore, ">= 0.0.0"} ] end @@ -104,7 +104,7 @@ To add this page, we will change the default landing page of our Phoenix app. Go the file with: ```html -<.flash_group flash={@flash} /> +

Redix Demo

@@ -137,8 +137,12 @@ the file with:
<% end %> +
``` +Since Phoenix 1.8, templates wrap their content in the `Layouts.app` component, +which renders the app layout and the flash messages. + This HTML will show different content depending on the parameters we pass it. It has a form at the top which is where the user will enter some location. Below, we will show the weather information. @@ -190,7 +194,7 @@ defmodule RedixDemoWeb.PageController do end defp render_home(conn, %Payload{} = payload) do - render(conn, "home.html", text: payload.text, weather: payload.weather, location: payload.location) + render(conn, :home, text: payload.text, weather: payload.weather, location: payload.location) end end ``` @@ -250,7 +254,7 @@ Once the app is launched, deploy it with: fly deploy ``` -The website will become avaiable after some time. Check the `/status` page to see that +The website will become available after some time. Check the `/status` page to see that the redis connection is correctly done. In the rest of our tutorial, we will work on caching the responses from an external api. @@ -381,7 +385,7 @@ Finally, we define the `get_weather_info` and `home` methods. To deploy the app after adding the home page logic, only a few steps remain to deploy the finished app. -First, add `{:httpoison, "~> 1.5"}` dependency to `mix.exs` file and run `mix deps.get`. +First, add `{:httpoison, "~> 3.0"}` dependency to `mix.exs` file and run `mix deps.get`. Then, get an API key from [WeatherAPI](https://www.weatherapi.com/) and set it as secret in fly with: diff --git a/redis/quickstarts/fastapi.mdx b/redis/quickstarts/fastapi.mdx index 5aab2a698..d14d47c16 100644 --- a/redis/quickstarts/fastapi.mdx +++ b/redis/quickstarts/fastapi.mdx @@ -3,7 +3,7 @@ title: "FastAPI" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -16,7 +16,7 @@ title: "FastAPI" Install FastAPI and `upstash-redis`. ```shell -pip install fastapi +pip install "fastapi[standard]" pip install upstash-redis ``` diff --git a/redis/quickstarts/fastlycompute.mdx b/redis/quickstarts/fastlycompute.mdx index f79977614..8a5261060 100755 --- a/redis/quickstarts/fastlycompute.mdx +++ b/redis/quickstarts/fastlycompute.mdx @@ -3,7 +3,7 @@ title: "Fastly" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -17,15 +17,15 @@ latency from all edge locations. Copy the `UPSTASH_REDIS_REST_URL` and ### Project Setup We will use Fastly CLI for deployment, so please install -[Fastly CLI](https://developer.fastly.com/reference/cli/). +[Fastly CLI](https://www.fastly.com/documentation/reference/cli/). -Create a folder for your project and run `fastly init`. Select `[2] JavaScript`, -then `[2] Empty starter for JavaScript` +Create a folder for your project and run `fastly compute init`. Select +`[2] JavaScript`, then `[2] Empty starter for JavaScript` ```shell > fastly compute init -Creating a new Compute@Edge project. +Creating a new Compute project. Press ^C at any time to quit. @@ -35,7 +35,7 @@ Author: [enes@upstash.com] Language: [1] Rust [2] JavaScript -[3] AssemblyScript (beta) +[3] Go [4] Other ('bring your own' Wasm binary) Choose option: [1] 2 Starter kit: @@ -44,7 +44,7 @@ Starter kit: overriding caching rules. https://github.com/fastly/compute-starter-kit-javascript-default [2] Empty starter for JavaScript - An empty application template for the Fastly Compute@Edge environment which simply + An empty application template for the Fastly Compute environment which simply returns a 200 OK response. https://github.com/fastly/compute-starter-kit-javascript-empty Choose option or paste git URL: [1] 2 @@ -116,6 +116,11 @@ async function handleRequest(event) { } ``` +Hardcoded credentials are fine for this quickstart, but in production store them +in a +[Fastly Secret Store](https://www.fastly.com/documentation/guides/compute/edge-data-storage/working-with-secret-stores/) +instead. + ### Deploy Deploy: `fastly compute deploy` diff --git a/redis/quickstarts/flask.mdx b/redis/quickstarts/flask.mdx index 3d51daa5a..dd07cbbfb 100644 --- a/redis/quickstarts/flask.mdx +++ b/redis/quickstarts/flask.mdx @@ -3,7 +3,7 @@ title: "Flask" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -61,7 +61,7 @@ python app.py Visit `http://127.0.0.1:5000/` in your browser, and you will see the `counter` increment with each refresh. -Code Breakdown +### Code Breakdown 1. **Redis Setup:** We first import Flask and the Upstash Redis client. Using `Redis.from_env()`, we initialize the connection to our Redis database using the environment variables exported earlier. 2. **Increment Counter:** Each time the root route (`/`) is accessed, Redis increments the `counter` key. This key-value pair is automatically created in Redis if it does not exist, and its value is incremented on each request. diff --git a/redis/quickstarts/fly.mdx b/redis/quickstarts/fly.mdx index 8fb499c36..d55f86e49 100755 --- a/redis/quickstarts/fly.mdx +++ b/redis/quickstarts/fly.mdx @@ -3,7 +3,7 @@ title: "Fly.io" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -11,7 +11,7 @@ title: "Fly.io" Fly.io has a native integration with Upstash where the databases are hosted in Fly. You can still access a Redis from Fly to Upstash but for the best latency, we recommend creating Redis (Upstash) inside Fly platform. Check - [here](https://fly.io/docs/reference/redis/) for details. + [here](https://fly.io/docs/upstash/redis/) for details. In this tutorial, we'll walk you through the process of deploying a Redis by @@ -22,25 +22,24 @@ adapted to other languages and frameworks. ### Redis Setup Create a Redis database using -[Fly CLI](https://fly.io/docs/hands-on/install-flyctl/) +[Fly CLI](https://fly.io/docs/flyctl/install/) ```shell > flyctl redis create ? Select Organization: upstash (upstash) ? Choose a Redis database name (leave blank to generate one): ? Choose a primary region (can't be changed later) San Jose, California (US) (sjc) - -Upstash Redis can evict objects when memory is full. This is useful when caching in Redis. This setting can be changed later. -Learn more at https://fly.io/docs/reference/redis/#memory-limits-and-object-eviction-policies -? Would you like to enable eviction? No ? Optionally, choose one or more replica regions (can be changed later): -? Select an Upstash Redis plan 3G: 3 GB Max Data Size +? Select an Upstash Redis plan Pay As You Go Your Upstash Redis database silent-tree-6201 is ready. Apps in the upstash org can connect to at redis://default:978ba2e07tyrt67598acd8ac916a@fly-silent-tree-6201.upstash.io If you have redis-cli installed, use fly redis connect to connect to your database. ``` +Upstash Redis on Fly.io offers a pay-as-you-go plan as well as fixed-size plans. +See [the Fly.io docs](https://fly.io/docs/upstash/redis/) for current pricing. + ### Set up the Node.js application - Create a new folder for your project and navigate to it in the terminal. @@ -50,23 +49,26 @@ If you have redis-cli installed, use fly redis connect to connect to your databa ```js const express = require("express"); -const redis = require("redis"); -const { promisify } = require("util"); +const { createClient } = require("redis"); const app = express(); -const client = redis.createClient(process.env.REDIS_URL); +const client = createClient({ url: process.env.REDIS_URL }); -const getAsync = promisify(client.get).bind(client); -const setAsync = promisify(client.set).bind(client); +client.on("error", (err) => console.error("Redis Client Error", err)); app.get("/", async (req, res) => { - const value = await getAsync("counter"); - await setAsync("counter", parseInt(value || 0) + 1); - res.send(`Hello, visitor number ${value || 0}!`); + const count = await client.incr("counter"); + res.send(`Hello, visitor number ${count}!`); }); const PORT = process.env.PORT || 3000; -app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); + +async function start() { + await client.connect(); + app.listen(PORT, () => console.log(`Server running on port ${PORT}`)); +} + +start(); ``` This code creates a simple Express server that increments a counter in Redis and @@ -74,18 +76,18 @@ returns the visitor number. ### Configure the Fly.io application -- Run `fly init "your-app-name"` to initialize a new Fly.io application. -- Choose the "Node.js (14.x)" builder, and accept the defaults for the remaining - prompts. -- Open the `fly.toml` file that was generated and add the following environment - variable under the `[[services]]` section: +- Run `fly launch` to initialize a new Fly.io application, and accept the + defaults for the prompts. +- Since the Redis URL contains your database password, store it as a secret + instead of putting it in `fly.toml`: -```toml -[env] - REDIS_URL = "" +```shell +fly secrets set REDIS_URL="" ``` Replace `your-upstash-redis-url` with the Redis URL from your Upstash instance. +The secret is made available to your application as the `REDIS_URL` environment +variable. ### Deploy the application to Fly.io @@ -101,87 +103,36 @@ You have successfully deployed a Node.js application on Fly.io that uses an Upstash Redis instance as its data store. You can now build and scale your application as needed, leveraging the benefits of both Fly.io and Upstash. -### Availability of Redis URL for Local Development and Testing - -#### Understanding Fly.io and Redis Setup - -- **Redis Instance on Fly.io**: When you create a Redis instance using `fly redis create`, Fly.io establishes a Redis server in its cloud environment, designed specifically for applications running on the Fly.io platform. - -- **Connection String**: This command generates a connection string. However, it's important to note that this string is intended primarily for applications deployed within Fly.io's network. Due to security and network configurations, it's not directly accessible from external networks, like your local development environment. - -#### Creating a Tunnel for Local Testing - -- **Fly Redis Connect**: For local access to your Redis instance, use `fly redis connect`. This command establishes a secure tunnel between your local machine and the Redis instance on Fly.io. - - - **How it Works**: - - The tunnel maps a local port to the remote Redis port on Fly.io. - - Once established, you can connect to Redis as if it were running locally, typically at `localhost` with the mapped port. - - - **Setting Up the Tunnel**: - - Execute `fly redis connect` in your terminal. - - The command provides a local address (e.g., `localhost:10000`). - - Use this address as your Redis connection URL in your local development setup. - - - **Considerations**: - - This tunnel is a temporary solution, ideal for development and testing, not for production. - - Ensure compatibility with your local firewall and network settings. - -#### Additional Notes +### Local Development -- **Security Considerations**: Exercise caution regarding security. Although the tunnel is secure, it exposes your Redis instance to your local network. -- **Alternative Approaches**: Some developers opt to run a local Redis instance for development to bypass these complexities. +Your database is only reachable over your Fly organization's private IPv6 network, so the `redis://...upstash.io` URL does not work from your local machine. For local development, Fly CLI can open a secure tunnel to the database. -#### Summary - -To connect to a Redis instance hosted on Fly.io from your local machine, a secure tunnel is necessary. This tunnel effectively simulates a local Redis instance, enabling testing and development activities without exposing your Redis instance over the internet. - -#### Example Code for Setting Up and Using the Fly.io Redis Tunnel - -##### Step 1: Establish the Tunnel - -To establish a tunnel between your local machine and the Redis instance on Fly.io, run the following command in your terminal: +#### Explore your data with redis-cli ```shell fly redis connect ``` -After running this command, you'll receive a local address, such as `localhost:10000`. This address will act as your local Redis endpoint. - -##### Step 2: Connect to Redis in Your Application - -In your application, you should typically use an environment variable for the Redis URL. When developing locally, set this environment variable to the local address provided by the `fly redis connect` command. - -Here's an example in a Node.js application: +This proxies local port `16379` to your database and opens an interactive `redis-cli` session, so you can inspect keys and run commands directly. -```js -const redis = require("redis"); - -// Local Redis URL for development -const LOCAL_REDIS_URL = 'redis://localhost:10000'; // Replace with your actual local address -const REDIS_URL = process.env.NODE_ENV === 'development' ? LOCAL_REDIS_URL : process.env.REDIS_URL; +#### Run your application against the tunnel -const client = redis.createClient({ - url: REDIS_URL -}); +To use the database from a locally running application, open a plain proxy instead: -client.on("error", function(error) { - console.error(error); -}); - -// Rest of your Redis-related code +```shell +fly redis proxy ``` -##### Step 3: Running Your Application Locally - -Ensure that the Fly.io Redis tunnel is active when you run your application locally. Your application will connect to Redis through this tunnel, simulating a local instance. +Keep it running, and point your application at `localhost:16379` using the password from your Redis URL: ```shell -npm start +REDIS_URL="redis://default:@localhost:16379" npm start ``` -**Important Notes:** +Since the application already reads `REDIS_URL` from the environment, no code changes are needed. -- The `fly redis connect` tunnel should only be used for development and testing purposes. -- Replace `LOCAL_REDIS_URL` in the sample code with the actual local address provided by `fly redis connect`. -- Set your application's environment to 'development' when running locally to use the local Redis URL. + + The tunnel is meant for development and testing, not production. For a fully + local setup, you can also run a local Redis server instead. + diff --git a/redis/quickstarts/google-cloud-functions.mdx b/redis/quickstarts/google-cloud-functions.mdx index 465caa72e..d55b09196 100644 --- a/redis/quickstarts/google-cloud-functions.mdx +++ b/redis/quickstarts/google-cloud-functions.mdx @@ -1,9 +1,9 @@ --- -title: "Google Cloud Functions" +title: "Google Cloud Run functions" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -15,7 +15,7 @@ title: "Google Cloud Functions" 1. [Create a Google Cloud Project.](https://cloud.google.com/resource-manager/docs/creating-managing-projects) 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/verify-billing-enabled#console) -3. Enable Cloud Functions, Cloud Build, Artifact Registry, Cloud Run, Logging, and Pub/Sub APIs. +3. [Enable the Cloud Run, Cloud Build, Artifact Registry, and Cloud Logging APIs.](https://console.cloud.google.com/flows/enableapi?apiid=run.googleapis.com,cloudbuild.googleapis.com,artifactregistry.googleapis.com,logging.googleapis.com) ### Database Setup @@ -23,15 +23,38 @@ Create a Redis database using [Upstash Console](https://console.upstash.com) or ### Counter Function Setup & Deploy -1. Go to [Cloud Functions](https://console.cloud.google.com/functions/list) in Google Cloud Console. -2. Click **Create Function**. -3. Setup **Basics and Trigger** Configuration like below: -![](/img/redis-gcloud/basics.png) -4. Using your `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`, setup **Runtime environment variables** under **Runtime, build, connections and privacy settings** like below. -![](/img/redis-gcloud/environment.png) -5. Click **Next**. -6. Set **Entry point** to `counter`. -7. Update `index.js` +Google Cloud Functions is now part of Cloud Run, as Cloud Run functions. You create and deploy functions from the Cloud Run console. + +1. Go to [Cloud Run](https://console.cloud.google.com/run) in Google Cloud Console. +2. Click **Write a function**. +3. Enter a service name, pick a region, and select a recent **Node.js** runtime. + + + + + +4. Under **Authentication**, select **Allow public access**. +5. Expand the **Containers, Volumes, Networking, Security** section. In the **Variables & Secrets** tab, add the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` environment variables with the values from your database. + + + + + +6. Click **Create**. The console creates the service and opens the inline source editor. +7. Set **Function entry point** to `counter`. + + + + + + + The entry point must match the name you register with + `functions.http('counter', ...)` below. If it stays at the default + `helloHttp`, the container starts no server and the deploy fails with a + "failed to start and listen on PORT 8080" error. + + +8. Update `index.js` ```js index.js const { Redis } = require("@upstash/redis"); const functions = require('@google-cloud/functions-framework'); @@ -46,14 +69,14 @@ functions.http('counter', async (req, res) => { res.send("Counter:" + count); }); ``` -8. Update `package.json` to include `@upstash/redis`. +9. Update `package.json` to include `@upstash/redis`. ```json package.json { "dependencies": { - "@google-cloud/functions-framework": "^3.0.0", - "@upstash/redis": "^1.31.6" + "@google-cloud/functions-framework": "^5.0.0", + "@upstash/redis": "^1.38.0" } } ``` -9. Click **Deploy**. -10. Visit the given URL. \ No newline at end of file +10. Click **Save and redeploy**. +11. Visit the URL shown at the top of the service page. \ No newline at end of file diff --git a/redis/quickstarts/koyeb.mdx b/redis/quickstarts/koyeb.mdx index a3b1e17b9..4aeddf899 100644 --- a/redis/quickstarts/koyeb.mdx +++ b/redis/quickstarts/koyeb.mdx @@ -3,7 +3,7 @@ title: "Koyeb" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -11,11 +11,11 @@ Integrate a serverless Upstash Redis database with your Koyeb applications. Comb This guide explains how to connect an Upstash Redis data store as a database cache with an application running on Koyeb. To successfully follow this documentation, you will need to have: -- A [Koyeb account](https://app.koyeb.com/) to deploy the application. You can optionally install the [Koyeb CLI](https://www.koyeb.com/docs/quickstart/koyeb-cli) to deploy the application from the command line +- A [Koyeb account](https://app.koyeb.com/) to deploy the application. You can optionally install the [Koyeb CLI](https://www.koyeb.com/docs/build-and-deploy/cli/installation) to deploy the application from the command line - An [Upstash account](https://console.upstash.com/) to deploy the database - [Node.js](https://nodejs.org/en) and `npm` installed on your local machine to create the demo application. -If you already have a freshly created Upstash Redis database running and want to quickly preview how to connect your Upstash database to an application running on Koyeb, use the [Deploy to Koyeb](https://www.koyeb.com/docs/deploy-to-koyeb-button) button below. +If you already have a freshly created Upstash Redis database running and want to quickly preview how to connect your Upstash database to an application running on Koyeb, use the [Deploy to Koyeb](https://www.koyeb.com/docs/build-and-deploy/deploy-to-koyeb-button) button below. [![Deploy to Koyeb](https://www.koyeb.com/static/images/deploy/button.svg)](https://app.koyeb.com/deploy?type=git&repository=github.com/koyeb/example-koyeb-upstash&branch=main&name=example-koyeb-upstash&env[UPSTASH_REDIS_REST_URL]=REPLACE_ME&env[UPSTASH_REDIS_REST_TOKEN]=REPLACE_ME&env[PORT]=8000) @@ -28,7 +28,7 @@ To create an Upstash Redis database, sign into your [Upstash account](https://co In the Upstash console, select **Redis** from the top navigation bar. On the Redis page, click **Create database**: 1. In the **Name** field, choose a name for your database. In this example, we'll use `example-koyeb-upstash`. -2. Select the **Type** of deployment you want. Because this is demo does not have global requirements, we will use "Regional" in this guide to limit the choices we have to make. +2. Select the **Type** of deployment you want. Because this demo does not have global requirements, we will use "Regional" in this guide to limit the choices we have to make. 3. In the **Region** drop-down menu, choose a location that's geographically convenient for your database and users. We use "N. Virginia (us-east-1)". 4. Select your preferred options. In this example, we will select "TLS (SSL) Enabled" so that connections to the database are encrypted and "Eviction" so that older data will be purged when we run out of space. 5. Click **Create** to provision the Redis database. @@ -84,9 +84,6 @@ npm install @upstash/redis express Now, create a new file called `index.js` with the following contents: ```javascript -// Note: if you are using Node.js version 17 or lower, -// change the first line to the following: -// const { Redis } = require ("@upstash/redis/with-fetch"); const { Redis } = require("@upstash/redis"); const express = require("express"); @@ -105,8 +102,6 @@ app.listen(PORT, () => { }); ``` -**Note:** If you are running Node.js version 17 or lower, you need to adjust the first line of the app to import from the `@upstash/redis/with-fetch` instead of `@upstash/redis`. Node.js versions prior to 18 did not natively support `fetch` API, so you need to change the import path in order to access that functionality. - This above code will introduce a simple `counter` key to your Redis database. It will use this key to store the number of times the page has been accessed and display that value on the page. ### Add the run scripts @@ -128,8 +123,8 @@ Finally, edit the `package.json` file to define the scripts used to run the appl "author": "", "license": "ISC", "dependencies": { - "@upstash/redis": "^1.20.6", - "express": "^4.18.2" + "@upstash/redis": "^1.38.0", + "express": "^5.0.0" } } ``` @@ -188,7 +183,7 @@ A Koyeb App and Service will be created. Your application will be built and depl ### Via the Koyeb CLI -To deploy the example application using the [Koyeb CLI](https://www.koyeb.com/docs/cli/installation), run the following command in your terminal: +To deploy the example application using the [Koyeb CLI](https://www.koyeb.com/docs/build-and-deploy/cli/installation), run the following command in your terminal: ```bash koyeb app init example-koyeb-upstash \ @@ -249,7 +244,7 @@ README.md Afterwards, create a `Dockerfile` in your project root directory and copy the content below: ```dockerfile -FROM node:18-alpine AS base +FROM node:22-alpine AS base FROM base AS deps RUN apk add --no-cache libc6-compat @@ -273,7 +268,7 @@ The Dockerfile above provides the minimum requirements to run the sample Node.js _Be sure to set the `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN` environment variables to the values you copied from the Upstash console when you deploy the container in the Koyeb control panel._ -To build and push the Docker image to a registry and deploy it on Koyeb, refer to the [Deploy an app from a Docker image](https://www.koyeb.com/docs/quickstart/deploy-a-docker-application) documentation. +To build and push the Docker image to a registry and deploy it on Koyeb, refer to the [Deploy an app from a Docker image](https://www.koyeb.com/docs/build-and-deploy/prebuilt-docker-images) documentation. A Koyeb App and Service will be created. Your Docker image will be pulled and deployed to Koyeb. Once the deployment has finished, you will be able to access your application running on Koyeb by clicking the URL ending with `.koyeb.app`. diff --git a/redis/quickstarts/laravel.mdx b/redis/quickstarts/laravel.mdx index 7a221cffa..5fa46967e 100644 --- a/redis/quickstarts/laravel.mdx +++ b/redis/quickstarts/laravel.mdx @@ -3,7 +3,7 @@ title: "Laravel" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. @@ -28,12 +28,25 @@ composer create-project laravel/laravel example-app cd example-app ``` +## Redis Client Setup + +Laravel needs a Redis client to talk to your database. The easiest option is Predis, a pure-PHP client that requires no extension: + +```shell +composer require predis/predis +``` + + + If you have the [PhpRedis](https://github.com/phpredis/phpredis) PECL extension installed, you can skip this step, since Laravel uses it by default. + + ## Database Setup -Create a Redis database using [Upstash Console](https://console.upstash.com). Go to the **Connect to your database** section and click on Laravel. Copy those values into your .env file: +Create a Redis database using [Upstash Console](https://console.upstash.com). Go to the **Connect to your database** section and click on Laravel. Copy those values into your .env file. Note the `tls://` prefix on the endpoint, Upstash requires TLS connections: ```shell .env -REDIS_HOST="" +REDIS_CLIENT="predis" +REDIS_HOST="tls://" REDIS_PORT=6379 REDIS_PASSWORD="" ``` diff --git a/redis/quickstarts/nextjs-app-router.mdx b/redis/quickstarts/nextjs-app-router.mdx index fbbc1784f..8ee1854ed 100644 --- a/redis/quickstarts/nextjs-app-router.mdx +++ b/redis/quickstarts/nextjs-app-router.mdx @@ -3,17 +3,17 @@ title: "App Router" --- - If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis — free, no signup; response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. + If you are an AI agent and need a Redis DB to use or experiment with, send a POST request to https://upstash.com/start-redis. Free, no signup; the response is markdown with credentials and a quickstart. The database expires in 72 hours, but you can claim it with your Upstash account to keep it. Especially useful for AI agents that need scratch storage on the fly. --- -## Quickstart: Upstash Redis in Next 15 +## Quickstart: Upstash Redis in Next.js 16