### Install Dependencies and Run App Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/nextjs.mdx Commands to install project dependencies and start the development server. ```bash yarn ``` ```bash yarn dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/cloud_run_sessions.mdx Initialize the Node.js project and install required packages. ```bash npm init npm install express redis connect-redis express-session ``` -------------------------------- ### Start Kafka Connector API Requests Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/kafka/connectors/start.mdx Examples of how to trigger the start of a Kafka connector using cURL, Python, and Go. ```shell curl -X POST \ https://api.upstash.com/v2/kafka/connector/:id/start \ -u 'EMAIL:API_KEY' ``` ```python import requests response = requests.post('https://api.upstash.com/v2/kafka/connector/:id/start', auth=('EMAIL', 'API_KEY')) response.content ``` ```go client := &http.Client{} req, err := http.NewRequest("POST", "https://api.upstash.com/v2/kafka/connector/:id/start", nil) if err != nil { log.Fatal(err) } req.SetBasicAuth("email", "api_key") resp, err := client.Do(req) if err != nil { log.Fatal(err) } bodyText, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText); ``` -------------------------------- ### Install QStash SDK Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/qstash/overview.mdx Installation command for npm environments. ```bash npm install @upstash/qstash ``` -------------------------------- ### Deployment Output Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/cloud_run_sessions.mdx Example output showing a successful deployment to Cloud Run. ```text Deploying container to Cloud Run service [cloud-run-sessions] in project [cloud-run-sessions] region [us-central1] ✓ Deploying... Done. ✓ Creating Revision... ✓ Routing traffic... ✓ Setting IAM Policy... Done. Service [cloud-run-sessions] revision [cloud-run-sessions-00006-dun] has been deployed and is serving 100 percent of traffic. Service URL: https://cloud-run-sessions-dr7fcdmn3a-uc.a.run.app ``` -------------------------------- ### Install Upstash Pulumi Provider for Go Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/devops/pulumi/overview.mdx Use go get to retrieve the latest version of the SDK. ```bash go get github.com/upstash/pulumi-upstash/sdk/go/... ``` -------------------------------- ### Install Upstash Ratelimit Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/ratelimit/gettingstarted.mdx Installation commands for npm and Deno environments. ```bash npm install @upstash/ratelimit ``` ```ts import { Ratelimit } from "https://cdn.skypack.dev/@upstash/ratelimit@latest"; ``` -------------------------------- ### Set up environment variables Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/nuxtjs.mdx Copy the example environment file to configure local variables. ```bash cp .env.local.example .env.local ``` -------------------------------- ### Create Kafka Topic Request Examples Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/kafka/topics/get.mdx Examples showing how to send a POST request to create a Kafka topic using different programming languages. ```shell curl -X POST \ https://api.upstash.com/v2/kafka/topic \ -u 'EMAIL:API_KEY' \ -d '{"name":"test-kafka-topic","partitions":1,"retention_time":1234,"retention_size":4567,"max_message_size":8912,"cleanup_policy":"delete","cluster_id":"9bc0e897-cbd3-4997-895a-fd77ad00aec9"}' ``` ```python import requests data = '{"name":"test-kafka-topic","partitions":1,"retention_time":1234,"retention_size":4567,"max_message_size":8912,"cleanup_policy":"delete","cluster_id":"9bc0e897-cbd3-4997-895a-fd77ad00aec9"}' response = requests.post('https://api.upstash.com/v2/kafka/topic', data=data, auth=('EMAIL', 'API_KEY')) response.content ``` ```go client := &http.Client{} var data = strings.NewReader(`{ "name": "test-kafka-topic", "partitions": 1, "retention_time": 1234, "retention_size": 4567, "max_message_size": 8912, "cleanup_policy": "delete", "cluster_id": "9bc0e897-cbd3-4997-895a-fd77ad00aec9" }`) req, err := http.NewRequest("POST", "https://api.upstash.com/v2/kafka/topic", data) if err != nil { log.Fatal(err) } req.SetBasicAuth("email", "api_key") resp, err := client.Do(req) if err != nil { log.Fatal(err) } bodyText, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText); ``` -------------------------------- ### Install Serverless Framework Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/auto_complete_with_serverless_redis.mdx Command to install the Serverless framework globally via npm. ```bash npm install -g serverless ``` -------------------------------- ### Pipeline Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/features/restapi.mdx A practical example demonstrating how to batch multiple Redis commands and handle the resulting response. ```redis SET key1 valuex SETEX key2 13 valuez INCR key1 ZADD myset 11 item1 22 item2 ``` ```shell curl -X POST https://us1-merry-cat-32748.upstash.io/pipeline \ -H "Authorization: Bearer 2553feg6a2d9842h2a0gcdb5f8efe9934" \ -d ' [ ["SET", "key1", "valuex"], ["SETEX", "key2", 13, "valuez"], ["INCR", "key1"], ["ZADD", "myset", 11, "item1", 22, "item2"] ] ' ``` ```json [ { "result": "OK" }, { "result": "OK" }, { "error": "ERR value is not an int or out of range" }, { "result": 2 } ] ``` -------------------------------- ### Install Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/histogram.mdx Install the required Redis client and histogram library. ```bash npm init ``` ```bash npm install ioredis npm install hdr-histogram-js ``` -------------------------------- ### Install required packages Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/recipes/periodic-data-updates.mdx Install the necessary Upstash QStash and Redis client libraries for the project. ```bash npm install @upstash/qstash @upstash/redis ``` -------------------------------- ### Install Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/quickstarts/aws-lambda/nodejs.mdx Install TypeScript type definitions and esbuild for bundling. ```bash npm install -D @types/aws-lambda @types/node esbuild ``` -------------------------------- ### Initialize Next.js Project and Install Redis Client Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/roadmapvotingapp.mdx Commands to scaffold a new Next.js application and install the ioredis client dependency. ```bash npx create-next-app nextjs-with-redis ``` ```bash npm install ioredis ``` -------------------------------- ### Initialize API Directory and Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/api_with_cdk.mdx Commands to set up the API subdirectory and install the ioredis client. ```bash cd api npm init npm install ioredis ``` -------------------------------- ### Add Start Script to package.json Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/cloud_run_sessions.mdx Define the start script in the package.json file. ```json "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node index" } ``` -------------------------------- ### Install Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/awslambda.mdx Commands to navigate to the project directory and install the Upstash Redis client. ```bash cd aws-node-http-api-project npm init -y npm install @upstash/redis ``` -------------------------------- ### Install Upstash Ratelimit Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/py/ratelimit/gettingstarted.mdx Install the package using pip. ```bash pip install upstash-ratelimit ``` -------------------------------- ### Install dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/koyeb.mdx Install the required Upstash Redis SDK and Express framework. ```bash npm install @upstash/redis express ``` -------------------------------- ### Create Maven Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkastreams.mdx Generate a new Maven project using the quickstart archetype. ```bash mvn archetype:generate -DgroupId=com.kafkastreamsinteg.app -DartifactId=kafkastreamsinteg-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false ``` -------------------------------- ### Install Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/rate-limiting.mdx Install the required Redis client, rate limiter, and IP detection libraries. ```bash npm install ioredis async-ratelimiter request-ip ``` -------------------------------- ### Installing the package Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/redis/getstarted.mdx Install the package using common Node.js package managers. ```bash npm install @upstash/redis ``` ```bash yarn add @upstash/redis ``` ```bash pnpm add @upstash/redis ``` -------------------------------- ### Run Development Server Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/tutorials/getstarted_nextjs_kafka.mdx Command to start the local development server. ```bash npm run dev ``` -------------------------------- ### Install Upstash Pulumi Provider for Python Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/devops/pulumi/overview.mdx Install the package using pip. ```bash pip install upstash_pulumi ``` -------------------------------- ### Start ksqlDB CLI Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkaksqldb.mdx Command to initiate the ksqlDB CLI session connected to the server. ```bash docker exec -it ksqldb-cli ksql http://ksqldb-server:8088 ``` -------------------------------- ### Run Development Server Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/nuxtjs.mdx Start the Nuxt.js development server. ```bash yarn dev ``` -------------------------------- ### Install Upstash Redis SDK Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/py/redis/gettingstarted.mdx Install the package using pip. ```bash pip install upstash-redis ``` -------------------------------- ### Install Mintlify CLI Source: https://github.com/ytkimirti/upstash-docs/blob/main/README.mdx Install the Mintlify CLI globally using npm to enable local previewing of documentation. ```bash npm i -g mintlify ``` -------------------------------- ### Fetch API Examples Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/rest/restconsumer.mdx Examples of using the Fetch API to retrieve messages from single or multiple topic partitions. ```shell curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/fetch -u myuser:mypass \ -d '{"topic": "greetings", "partition": 3, "offset": 11, "timeout": 1000}' ``` ```shell curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/fetch -u myuser:mypass \ -d '{ "topicPartitionOffsets": [ {"topic": "greetings", "partition": 1, "offset": 1}, {"topic": "greetings", "partition": 2, "offset": 1}, {"topic": "greetings", "partition": 3, "offset": 1}, {"topic": "cities", "partition": 1, "offset": 10}, {"topic": "cities", "partition": 2, "offset": 20} ], "timeout": 5000 }' ``` ```shell curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/fetch -u myuser:mypass \ -d '{ "topic": "words", "partition": 0, "offset": 0, "topicPartitionOffsets": [ {"topic": "cities", "partition": 1, "offset": 10}, {"topic": "cities", "partition": 2, "offset": 20} ], "timeout": 5000 }' ``` -------------------------------- ### Configure package.json run scripts Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/koyeb.mdx Add start and dev scripts to the package.json file. ```diff { "name": "example-koyeb-upstash", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { + "dev": "DEBUG=express:* node index.js", + "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@upstash/redis": "^1.20.6", "express": "^4.18.2" } } ``` -------------------------------- ### Install Edge Flags SDK Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/edge-flags/getstarted.mdx Install the required package using npm. ```bash npm install @upstash/edge-flags ``` -------------------------------- ### Start ksqlDB services Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/real-time-analytics/ksqldb.mdx Command to initialize the ksqlDB environment using Docker Compose. ```shell docker-compose up ``` -------------------------------- ### SDIFFSTORE usage example Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/redis/commands/set/sdiffstore.mdx Demonstrates adding members to sets and calculating the difference between them. ```ts await redis.sadd("set1", "a", "b", "c"); await redis.sadd("set2", "c", "d", "e"); await redis.sdiff("dest", "set1", "set2"); console.log(diff); // ["a", "b"] ``` -------------------------------- ### Install fetch polyfill for Node.js Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/redis/troubleshooting.mdx Install the isomorphic-fetch package to support fetch in Node.js environments earlier than v18. ```bash npm i isomorphic-fetch ``` -------------------------------- ### Install ioredis Dependency Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/using_aws_sam.mdx Install the ioredis client within the project directory. ```shell npm install ioredis ``` -------------------------------- ### Install @upstash/query dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/query/overview.mdx Install the required packages using your preferred package manager. ```bash pnpm add @upstash/query @upstash/redis ``` ```bash npm install @upstash/query @upstash/redis ``` ```bash bun install @upstash/query @upstash/redis ``` ```bash yarn add @upstash/query @upstash/redis ``` -------------------------------- ### Initialize Node.js Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/howto/getstartedawslambda.mdx Commands to initialize a new Node.js project and install the ioredis dependency. ```bash npm init ``` ```bash npm install ioredis ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/supabase.mdx Copy the example environment file to the local function directory. ```shell cp supabase/functions/upstash-redis-counter/.env.example supabase/functions/upstash-redis-counter/.env ``` -------------------------------- ### Verify Maven Installation Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkastreams.mdx Check the installed version of Maven to ensure the environment is ready for project creation. ```text Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: D:\apache-maven-3.6.3\apache-maven\bin\.. Java version: 1.8.0_232, vendor: AdoptOpenJDK, runtime: C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\jre Default locale: en_US, platform encoding: Cp1250 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows" ``` -------------------------------- ### ZINTERSTORE usage examples Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/redis/commands/zset/zinterstore.mdx Examples demonstrating basic intersection, applying weights, and using aggregation methods with ZINTERSTORE. ```ts await redis.zadd( "key1", { score: 1, member: "member1" }, ) await redis.zadd( "key2", { score: 1, member: "member1" }, { score: 2, member: "member2" }, ) const res = await redis.zinterstore("destination", 2, ["key1", "key2"]); console.log(res) // 1 ``` ```ts await redis.zadd( "key1", { score: 1, member: "member1" }, ) await redis.zadd( "key2", { score: 1, member: "member1" }, { score: 2, member: "member2" }, ) const res = await redis.zinterstore( "destination", 2, ["key1", "key2"], { weights: [2, 3] }, ); console.log(res) // 1 ``` ```ts await redis.zadd( "key1", { score: 1, member: "member1" }, ) await redis.zadd( "key2", { score: 1, member: "member1" }, { score: 2, member: "member2" }, ) const res = await redis.zinterstore( "destination", 2, ["key1", "key2"], { aggregate: "sum" }, ); console.log(res) // 1 ``` -------------------------------- ### Initialize Project Directory Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/cloud_run_sessions.mdx Create and enter the project directory. ```bash mkdir cloud-run-sessions cd cloud-run-sessions ``` -------------------------------- ### Start Apache Pinot Services Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkapinot.mdx Launch the defined services using Docker Compose. ```bash docker-compose --project-name pinot-demo up ``` -------------------------------- ### Get User Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/api-reference/endpoint/get.mdx Example JSON response returned by the API. ```json { "success": 1, "new_user_group": true, "user_group": { "team_id": 3, "token": "", "name": "Example 1", "provided_id": "example_1" } } ``` -------------------------------- ### List Topics Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/rest/restmetadata.mdx Example JSON response for the GET /topics endpoint. ```json { "cities": 12, "greetings": 1, "words": 137 } ``` -------------------------------- ### List Consumers JSON Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/rest/restmetadata.mdx Example JSON response for the GET /consumers endpoint. ```json [ { "name": "mygroup", "instances": [ { "name": "instance-1", "topics": [ { "topic": "cities", "partitions": [0, 1, 2] }, { "topic": "words", "partitions": [10, 21, 32] } ] }, { "name": "instance-2", "topics": [ { "topic": "cities", "partitions": [3, 4, 5] }, { "topic": "words", "partitions": [1, 3, 5, 7] } ] } ] } ] ``` -------------------------------- ### Initialize Go Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/quickstarts/fly-io/go.mdx Commands to create a new directory and initialize a Go module. ```bash mkdir flyio-go cd flyio-go go mod init flyio-go ``` -------------------------------- ### Troubleshoot Mintlify Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/README.mdx Re-install dependencies if the development server fails to start. ```bash mintlify install ``` -------------------------------- ### Deployment Output Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/serverless_java_redis.mdx Example output after deploying the service to AWS. ```shell Serverless: Stack update finished... Service Information service: serverless-api-java-redis stage: dev region: us-east-1 stack: serverless-api-java-redis-dev resources: 11 api keys: None endpoints: GET - https://60tinzba0a.execute-api.us-east-1.amazonaws.com/hello functions: hello: serverless-api-java-redis-dev-hello layers: None ``` -------------------------------- ### Start Development Server Source: https://github.com/ytkimirti/upstash-docs/blob/main/README.mdx Run the development server from the root directory containing the mint.json file. ```bash mintlify dev ``` -------------------------------- ### Successful Response Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/kafka/clusters/get.mdx The JSON structure returned upon a successful GET request. ```json { "cluster_id": "9bc0e897-cbd3-4997-895a-fd77ad00aec9", "name": "test_kafka_cluster", "region": "eu-west-1", "type": "paid", "multizone": true, "tcp_endpoint": "sharing-mastodon-12819-eu1-kafka.upstashdev.com", "rest_endpoint": "sharing-mastodon-12819-eu1-rest-kafka.upstashdev.com", "state": "active", "username": "c2hhcmluZy1tYXN0b2Rvbi0xMjgxOSRV1ipriSBOwd0PHzw2KAs_cDrTXzvUKIs", "password": "zlQgc0nbgcqF6MxOqnh7tKjJsGnSgLFS89uS-FXzMVqhL2dgFbmHwB-IXAAsOYXzUYj40g==", "max_retention_size": 1073741824000, "max_retention_time": 2592000000, "max_messages_per_second": 1000, "creation_time": 1643978975, "max_message_size": 1048576, "max_partitions": 100 } ``` -------------------------------- ### Connect using Redigo Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/howto/connectclient.mdx Go client example demonstrating manual dial and authentication steps. ```go func main() { c, err := redis.Dial("tcp", "YOUR_ENDPOINT:YOUR_PORT") if err != nil { panic(err) } _, err = c.Do("AUTH", "YOUR_PASSWORD") if err != nil { panic(err) } _, err = c.Do("SET", "foo", "bar") if err != nil { panic(err) } value, err := redis.String(c.Do("GET", "foo")) if err != nil { panic(err) } println(value) } ``` -------------------------------- ### Get User Request Source: https://github.com/ytkimirti/upstash-docs/blob/main/api-reference/endpoint/get.mdx Example request using cURL to retrieve or create a user. ```bash curl --location --request GET 'https://api.mintlify.com/api/user' \ --header 'Content-Type: application/json' \ --header 'Authorization: Token ' \ --data-raw '{ "user_group_id": "example_1", "name": "Example 1", "mapping": {"40": "213", "134": "386"}, "properties": {"filterValue": "value"} }' ``` -------------------------------- ### Transaction Example Request Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/features/restapi.mdx A concrete example of sending multiple Redis commands including SET, SETEX, INCR, and ZADD. ```shell curl -X POST https://us1-merry-cat-32748.upstash.io/multi-exec \ -H "Authorization: Bearer 2553feg6a2d9842h2a0gcdb5f8efe9934" \ -d ' [ ["SET", "key1", "valuex"], ["SETEX", "key2", 13, "valuez"], ["INCR", "key1"], ["ZADD", "myset", 11, "item1", 22, "item2"] ] ' ``` -------------------------------- ### Get Unwrapped Schema Success Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/schema-registry/schemarest.mdx Example JSON response for an unwrapped schema lookup. ```json { "type": "record", "name": "test", "fields": [ { "name": "field1", "type": "string" } ] } ``` -------------------------------- ### Install Upstash Pulumi Provider for Node.js Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/devops/pulumi/overview.mdx Use npm or yarn to install the package for TypeScript or JavaScript projects. ```bash npm install @upstash/pulumi ``` ```bash yarn add @upstash/pulumi ``` -------------------------------- ### Get Schema by ID Success Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/schema-registry/schemarest.mdx Example JSON response for a schema lookup by ID. ```json { "schema": "{\"type\":\"record\",\"name\":\"test\",\"fields\":[{\"name\":\"field1\",\"type\":\"string\"}]}" } ``` -------------------------------- ### Get All Schemas Success Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/schema-registry/schemarest.mdx Example JSON response containing a list of registered schemas. ```json [ { "subject": "subject1", "version": 1, "id": 1, "schemaType": "AVRO", "schema": "{\"type\":\"record\",\"name\":\"test\",\"fields\":[{\"name\":\"field1\",\"type\":\"string\"}]}" }, { "subject": "subject2", "version": 1, "id": 2, "schemaType": "AVRO", "schema": "{\"type\":\"record\",\"name\":\"test\",\"fields\":[{\"name\":\"field1\",\"type\":\"string\"},{\"name\":\"field2\",\"type\":\"string\",\"default\":\"x\"}]}" } ] ``` -------------------------------- ### Configure Lambda Handler Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/using_serverless_framework.mdx Example handler.js implementation using ioredis to set and get values from Upstash. ```javascript var Redis = require("ioredis"); if (typeof client === "undefined") { var client = new Redis(REDIS_URL); } module.exports.hello = async (event) => { await client.set("foo", "bar"); let response = await client.get("foo"); return { response: response }; }; ``` -------------------------------- ### Initialize Serverless Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/_snippets/kafka/awslambda.mdx Commands to scaffold a new Serverless Framework project and install the required axios dependency. ```shell kafka-examples git:(master) serverless What do you want to make? AWS - Node.js - HTTP API What do you want to call this project? produce-in-lambda Downloading "aws-node-http-api" template... Project successfully created in produce-in-lambda folder ``` ```shell npm init npm install axios ``` -------------------------------- ### Run Function Locally Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/supabase.mdx Start the Supabase environment and serve the function locally. ```bash supabase start supabase functions serve upstash-redis-counter --no-verify-jwt --env-file supabase/functions/upstash-redis-counter/.env ``` -------------------------------- ### Install Toast Component Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/notification.mdx Add react-toastify to the project for displaying notifications. ```shell npm install --save react-toastify ``` -------------------------------- ### Get Kafka Connector API Requests Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/kafka/connectors/get.mdx Examples for retrieving connector details using cURL, Python, and Go. ```shell curl -X GET \ https://api.upstash.com/v2/kafka/connector/:id \ -u 'EMAIL:API_KEY' ``` ```python import requests response = requests.get('https://api.upstash.com/v2/kafka/connector/:id', auth=('EMAIL', 'API_KEY')) response.content ``` ```go client := &http.Client{} req, err := http.NewRequest("GET", "https://api.upstash.com/v2/kafka/connector/:id", nil) if err != nil { log.Fatal(err) } req.SetBasicAuth("email", "api_key") resp, err := client.Do(req) if err != nil { log.Fatal(err) } bodyText, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText); ``` -------------------------------- ### Initialize and push Git repository Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/koyeb.mdx Prepare the project for deployment by initializing a Git repository and pushing it to GitHub. ```bash git init echo 'node_modules' >> .gitignore git add . git commit -m "Initial commit" git remote add origin git@github.com:/.git git push -u origin main ``` -------------------------------- ### Get Team Members Response Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/teams/get_team_members.mdx A successful response returns an array of objects containing team and member details. ```json [ { "team_id": "3423cb72-e50d-43ec-a9c0-f0f359941223", "team_name": "test_team_name_2", "member_email": "example@upstash.com", "member_role": "dev" }, { "team_id": "3423cb72-e50d-43ec-a9c0-f0f359941223", "team_name": "test_team_name_2", "member_email": "example_2@upstash.com", "member_role": "owner" } ] ``` -------------------------------- ### Get Kafka Connector Response Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/kafka/connectors/get.mdx A successful 200 OK response containing connector metadata and configuration properties. ```json { "connector_id": "431ec970-b59d-4b00-95fe-5f3abcc52c2f", "name": "connectorName", "customer_id": "EMAIL", "cluster_id": "7568431c-88d5-4409-a808-2167f22a7133", "creation_time": 1684369147, "deletion_time": 0, "state": "failed", "state_error_message": "Connector configuration is invalid and contains the following 1 error(s):\nInvalid value connection-uri-update for configuration connection.uri: The connection string is invalid. Connection strings must start with either 'mongodb://' or 'mongodb+srv://\n", "connector_state": "", "tasks": [], "topics": [], "connector_class": "com.mongodb.kafka.connect.MongoSourceConnector", "properties": { "connection.uri": "connection-uri-update", "connector.class": "com.mongodb.kafka.connect.MongoSourceConnector" }, "encoded_username": "YXBwYXJlbnQta2l0ZS0xMTMwMiTIqFhTItzgDdE56au6LgnnbtlN7ITzh4QATDw" } ``` -------------------------------- ### Initialize Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/quickstarts/aws-lambda/nodejs.mdx Commands to create a new directory and initialize a Node.js project. ```bash mkdir aws-lambda cd aws-lambda npm init -y ``` -------------------------------- ### Get Team Members API Request Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/teams/get_team_members.mdx Examples of how to authenticate and request team member data using various programming languages. ```shell curl -X GET \ https://api.upstash.com/v2/teams/:id \ -u 'EMAIL:API_KEY' ``` ```python import requests response = requests.get('https://api.upstash.com/v2/teams/:id', auth=('EMAIL', 'API_KEY')) response.content ``` ```go client := &http.Client{} req, err := http.NewRequest("GET", "https://api.upstash.com/v2/teams/:id", nil) if err != nil { log.Fatal(err) } req.SetBasicAuth("email", "api_key") resp, err := client.Do(req) if err != nil { log.Fatal(err) } bodyText, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText); ``` -------------------------------- ### Example Container Status Output Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkapinot.mdx Expected output after running the container list command. ```text CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ba5cb0868350 apachepinot/pinot:0.9.3 "./bin/pinot-admin.s…" About a minute ago Up About a minute 8096-8099/tcp, 9000/tcp pinot-server 698f160852f9 apachepinot/pinot:0.9.3 "./bin/pinot-admin.s…" About a minute ago Up About a minute 8096-8098/tcp, 9000/tcp, 0.0.0.0:8099->8099/tcp, :::8099->8099/tcp pinot-broker b1ba8cf60d69 apachepinot/pinot:0.9.3 "./bin/pinot-admin.s…" About a minute ago Up About a minute 8096-8099/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp pinot-controller 54e7e114cd53 zookeeper:3.5.6 "/docker-entrypoint.…" About a minute ago Up About a minute 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp pinot-zookeeper ``` -------------------------------- ### Initialize React Application Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/notification.mdx Create a new React project using npx. ```shell npx create-react-app serverless-notification-api ``` -------------------------------- ### List Kafka Topics API Request Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/kafka/topics/list.mdx Examples of how to perform the GET request to list Kafka topics using different programming languages. ```shell curl -X GET \ https://api.upstash.com/v2/kafka/topics/:id \ -u 'EMAIL:API_KEY' ``` ```python import requests response = requests.get('https://api.upstash.com/v2/kafka/topics/:id', auth=('EMAIL', 'API_KEY')) response.content ``` ```go client := &http.Client{} req, err := http.NewRequest("GET", "https://api.upstash.com/v2/kafka/topics/:id", nil) if err != nil { log.Fatal(err) } req.SetBasicAuth("email", "api_key") resp, err := client.Do(req) if err != nil { log.Fatal(err) } bodyText, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", bodyText); ``` -------------------------------- ### Initialize AWS SAM Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/using_aws_sam.mdx Run the sam init command to start a new serverless project using the Hello World template. ```shell ➜ serverless-tutorials > ✗ sam init SAM CLI now collects telemetry to better understand customer needs. You can OPT OUT and disable telemetry collection by setting the environment variable SAM_CLI_TELEMETRY=0 in your shell. Thanks for your help! Learn More: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-telemetry.html Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: 1 What package type would you like to use? 1 - Zip (artifact is a zip uploaded to S3) 2 - Image (artifact is an image uploaded to an ECR image repository) Package type: 1 Which runtime would you like to use? 1 - nodejs14.x 2 - python3.8 3 - ruby2.7 4 - go1.x 5 - java11 6 - dotnetcore3.1 7 - nodejs12.x 8 - nodejs10.x 9 - python3.7 10 - python3.6 11 - python2.7 12 - ruby2.5 13 - java8.al2 14 - java8 15 - dotnetcore2.1 Runtime: 1 Project name [sam-app]: using-aws-sam Cloning app templates from https://github.com/aws/aws-sam-cli-app-templates AWS quick start application templates: 1 - Hello World Example 2 - Step Functions Sample App (Stock Trader) 3 - Quick Start: From Scratch 4 - Quick Start: Scheduled Events 5 - Install 5 - Quick Start: S3 6 - Quick Start: SNS 7 - Quick Start: SQS 8 - Quick Start: Web Backend Template selection: 1 ----------------------- Generating application: ----------------------- Name: using-aws-sam Runtime: nodejs14.x Dependency Manager: npm Application Template: hello-world Output Directory: . Next steps can be found in the README file at ./using-aws-sam/README ``` -------------------------------- ### Install @upstash/kafka Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/howto/connectwithupstashkafka.mdx Install the package via npm. ```bash npm install @upstash/kafka ``` -------------------------------- ### Initialize ksqlDB Client Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkaksqldb.mdx Configure and create a new ksqlDB client instance pointing to the server host and port. ```java String KSQLDB_SERVER_HOST = "localhost"; int KSQLDB_SERVER_HOST_PORT = 8088; ClientOptions options = ClientOptions.create() .setHost(KSQLDB_SERVER_HOST) .setPort(KSQLDB_SERVER_HOST_PORT); Client client = Client.create(options); ``` -------------------------------- ### Initialize AWS Lambda Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/quickstarts/aws-lambda/python.mdx Commands to create a project directory and the main Python file. ```bash mkdir aws-lambda cd aws-lambda touch lambda_function.py ``` -------------------------------- ### Example log output Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/quickstarts/deno-deploy.mdx Shows the expected output in the Deno Deploy logs after a successful request. ```bash europe-west3isolate start time: 2.21 ms Listening on http://localhost:8000/ The signature was valid ``` -------------------------------- ### Initialize Fly.io App Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/quickstarts/fly-io/go.mdx Use the flyctl CLI to launch a new application and generate the necessary configuration files. ```bash $ flyctl launch Creating app in /Users/andreasthomas/github/upstash/qstash-examples/fly.io/go Scanning source code Detected a Go app Using the following build configuration: Builder: paketobuildpacks/builder:base Buildpacks: gcr.io/paketo-buildpacks/go ? App Name (leave blank to use an auto-generated name): Automatically selected personal organization: Andreas Thomas ? Select region: fra (Frankfurt, Germany) Created app winer-cherry-9545 in organization personal Wrote config file fly.toml ? Would you like to setup a Postgresql database now? No ? Would you like to deploy now? No Your app is ready. Deploy with `flyctl deploy` ``` -------------------------------- ### Transaction Example Response Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/features/restapi.mdx The JSON response corresponding to the example transaction request. ```json [ { "result": "OK" }, { "result": "OK" }, { "error": "ERR value is not an int or out of range" }, { "result": 2 } ] ``` -------------------------------- ### Install Upstash Redis SDK Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/fastlycompute.mdx Install the required dependency for interacting with Upstash Redis. ```shell npm install @upstash/redis ``` -------------------------------- ### Initialize Next.js Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/tutorials/getstarted_nextjs_kafka.mdx Command to scaffold a new Next.js application. ```bash ➜ kafka-examples git:(master) ✗ npx create-next-app@latest ✔ What is your project named? … getstarted-nextjs Creating a new Next.js app in /Users/enes/dev/kafka-examples/getstarted-nextjs. ``` -------------------------------- ### Install Upstash CLI via npm Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/devops/cli/overview.mdx Installs the CLI globally on the system path. ```bash npm i -g @upstash/cli ``` -------------------------------- ### Install Conduktor on macOS Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/howto/monitorwith_conduktor.mdx Use Homebrew to install the Conduktor desktop application on a Mac. ```shell brew tap conduktor/brew brew install conduktor ``` -------------------------------- ### Configure Google Cloud SDK Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/cloud_run_sessions.mdx Set the project and enable necessary Google Cloud services. ```bash gcloud config set project cloud-run-sessions gcloud services enable run.googleapis.com gcloud services enable cloudbuild.googleapis.com ``` -------------------------------- ### JWT Payload Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/features/security.mdx An example of the payload section of the JWT sent in the Upstash-Signature header. ```json { "iss": "Upstash", "sub": "https://qstash-remote.requestcatcher.com/test", "exp": 1656580612, "nbf": 1656580312, "iat": 1656580312, "jti": "jwt_67kxXD6UBAk7DqU6hzuHMDdXFXfP", "body": "qK78N0k3pNKI8zN62Fq2Gm-_LtWkJk1z9ykio3zZvY4=" } ``` -------------------------------- ### JWT Header Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/features/security.mdx An example of the header section of the JWT sent in the Upstash-Signature header. ```json { "alg": "HS256", "typ": "JWT" } ``` -------------------------------- ### Produce Message Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/rest/restintro.mdx Example cURL command to produce a message to a specific topic. ```shell curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/produce/mytopic/hello_kafka -u myuser:mypass ``` -------------------------------- ### Upstash-Retried header examples Source: https://github.com/ytkimirti/upstash-docs/blob/main/qstash/features/retry.mdx Examples of the Upstash-Retried header values indicating the current attempt count. ```text Upstash-Retried: 0 // This is the first attempt Upstash-Retried: 1 // This request has been sent once before and now is the second attempt Upstash-Retried: 2 // This request has been sent twice before and now is the third attempt ``` -------------------------------- ### Initialize Serverless Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/awslambda.mdx Command to scaffold a new AWS Node.js HTTP API project using the Serverless Framework. ```shell npx serverless Creating a new serverless project ? What do you want to make? AWS - Node.js - HTTP API ? What do you want to call this project? aws-node-http-api-project ✔ Project successfully created in aws-node-http-api-project folder ? Do you want to login/register to Serverless Dashboard? No ? Do you want to deploy now? No What next? Run these commands in the project directory: serverless deploy Deploy changes serverless info View deployed endpoints and resources serverless invoke Invoke deployed functions serverless --help Discover more commands ``` -------------------------------- ### Initialize and Use Ratelimit Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/py/ratelimit/gettingstarted.mdx Configure the ratelimiter with a Redis instance and a window strategy, then check request allowance. ```python from upstash_ratelimit import Ratelimit, FixedWindow from upstash_redis import Redis # Create a new ratelimiter, that allows 10 requests per 10 seconds ratelimit = Ratelimit( redis=Redis.from_env(), limiter=FixedWindow(max_requests=10, window=10), # Optional prefix for the keys used in Redis. This is useful # if you want to share a Redis instance with other applications # and want to avoid key collisions. The default prefix is # "@upstash/ratelimit" prefix="@upstash/ratelimit", ) # Use a constant string to limit all requests with a single ratelimit # Or use a user ID, API key or IP address for individual limits. identifier = "api" response = ratelimit.limit(identifier) if not response.allowed: print("Unable to process at this time") else: do_expensive_calculation() print("Here you go!") ``` -------------------------------- ### Consume Messages Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/rest/restintro.mdx Example cURL command to consume messages from a topic using a consumer group. ```shell curl https://tops-stingray-7863-eu1-rest-kafka.upstash.io/consume/mygroup/mygroup_instance0/mytopic -u myuser:mypass ``` -------------------------------- ### Initialize package.json Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/quickstarts/koyeb.mdx Generate a default package.json file for the project. ```bash npm init -y ``` -------------------------------- ### GET /produce/$TOPIC/$MESSAGE Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/rest/restproducer.mdx Sends a single message to a specific topic using HTTP GET. ```APIDOC ## GET /produce/$TOPIC/$MESSAGE ### Description Sends a single message to a topic using HTTP GET. Optionally, a message key can be provided as a query parameter. ### Method GET ### Endpoint /produce/$TOPIC/$MESSAGE ### Parameters #### Path Parameters - **$TOPIC** (string) - Required - The name of the Kafka topic. - **$MESSAGE** (string) - Required - The message content to send. #### Query Parameters - **key** (string) - Optional - The message key. ### Response #### Success Response (200) - **topic** (string) - The topic name. - **partition** (int) - The partition ID. - **offset** (long) - The message offset. - **timestamp** (long) - The message timestamp. ``` -------------------------------- ### Create Serverless Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/serverless_java_redis.mdx Initialize a new Serverless Framework project using the AWS Java Maven template. ```shell serverless create --template aws-java-maven --name serverless-api-java-redis -p serverless-api-java-redis ``` -------------------------------- ### Install CDK Infrastructure Dependencies Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/api_with_cdk.mdx Commands to install the necessary AWS CDK libraries for Lambda and API Gateway. ```bash cd .. npm install @aws-cdk/aws-apigateway @aws-cdk/aws-lambda ``` -------------------------------- ### Create Next.js Project Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/tutorials/nextjs.mdx Initialize a new Next.js project using the Upstash example template. ```bash npx create-next-app -e https://github.com/upstash/examples/tree/master/nextjs-with-redis nextjs-with-redis ``` -------------------------------- ### Initialize QStash Client Source: https://github.com/ytkimirti/upstash-docs/blob/main/redis/howto/vercelintegration.mdx Initializes the QStash client using the QSTASH_TOKEN environment variable. ```ts import { Client } from "@upstash/qstash"; const c = new Client({ token: process.env.QSTASH_TOKEN, }); const res = await c.publishJSON({ url: "https://my-api...", body: { hello: "world", }, }); ``` -------------------------------- ### redis.xrange(key, start, end, count?) Source: https://github.com/ytkimirti/upstash-docs/blob/main/oss/sdks/ts/redis/commands/stream/xrange.mdx Retrieves stream entries from the specified key between the start and end IDs. ```APIDOC ## redis.xrange(key, start, end, count?) ### Description Returns stream entries matching a given range of IDs from a Redis stream. ### Parameters - **key** (string) - Required - The key of the stream. - **start** (string) - Required - The stream entry ID to start from. - **end** (string) - Required - The stream entry ID to end at. - **count** (integer) - Optional - The maximum number of entries to return. ### Response - **Record>** - An object of stream entries, keyed by their stream ID. ### Example ```ts const entries = redis.xrange(key, "-", "+"); console.log(entries); // { // "1548149259438-0": { // "field1": "value1", // "field2": "value2" // }, // "1548149259438-1": { // "field1": "value3", // "field2": "value4" // } // } ``` ``` -------------------------------- ### List Databases Response Example Source: https://github.com/ytkimirti/upstash-docs/blob/main/devops/developer-api/redis/list_databases.mdx A successful response returns an array of database objects containing configuration and connection details. ```json [ { "database_id": "96ad0856-03b1-4ee7-9666-e81abd0349e1", "database_name": "MyRedis", "database_type": "Pay as You Go", "region": "eu-central-1", "port": 30143, "creation_time": 1658909671, "state": "active", "password": "038a8e27c45e43068d5f186085399884", "user_email": "example@upstash.com", "endpoint": "eu2-sought-mollusk-30143.upstash.io", "tls": true, "rest_token": "AXW_ASQgOTZhZDA4NTYtMDNiMS00ZWU3LTk2NjYtZTgxYWJkMDM0OWUxMDM4YThlMjdjNDVlNDMwNjhkNWYxODYwODUzOTk4ODQ=", "read_only_rest_token": "AnW_ASQgOTZhZDA4NTYtMDNiMS00ZWU3LTk2NjYtZTgxYWJkMDM0OWUx8sbmiEcMm9u7Ks5Qx-kHNiWr_f-iUXSIH8MlziKMnpY=" } ] ``` -------------------------------- ### Start and Manage Kafka Streams Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkastreams.mdx Initializes and starts the Kafka Streams application with a shutdown hook for graceful termination. ```java final KafkaStreams streams = new KafkaStreams(topology, props); final CountDownLatch latch = new CountDownLatch(1); try { streams.start(); System.out.println("streams started"); latch.await(); } catch (final Throwable e) { System.exit(1); } Runtime.getRuntime().addShutdownHook(new Thread("streams-word-count") { @Override public void run() { streams.close(); latch.countDown(); } }); ``` -------------------------------- ### Execute Flink pipeline Source: https://github.com/ytkimirti/upstash-docs/blob/main/kafka/integrations/kafkaflink.mdx Starts the execution of the Flink job. ```java env.execute(); ```