Documentation Index Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
GitHub Repository You can find the project source code on GitHub.
Prerequisites
Create an Azure account.
Set up Azure CLI
Install the Azure Functions Core Tools
Project Setup
Initialize the project:
Install @upstash/redis
npm install @upstash/redis
Counter Function Setup
Create a new function from template.
func new --name CounterFunction --template "HTTP trigger" --authlevel "anonymous"
Update /src/functions/CounterFunction.ts
/src/functions/CounterFunction.ts
import { app , HttpRequest , HttpResponseInit , InvocationContext } from "@azure/functions" ;
import { Redis } from "@upstash/redis" ;
const redis = new Redis ({
url: process . env . UPSTASH_REDIS_REST_URL ,
token: process . env . UPSTASH_REDIS_REST_TOKEN
});
export async function CounterFunction ( request : HttpRequest , context : InvocationContext ) : Promise < HttpResponseInit > {
const count = await redis . incr ( "counter" );
return { status: 200 , body: `Counter: ${ count } ` };
};
app . http ( 'CounterFunction' , {
methods: [ 'GET' , 'POST' ],
authLevel: 'anonymous' ,
handler: CounterFunction
});
Create Azure Resources
You can use the command below to find the name of a region near you.
az account list-locations
Create a resource group.
az group create --name AzureFunctionsQuickstart-rg --location < REGIO N >
Create a storage account.
az storage account create --name < STORAGE_NAM E > --location < REGIO N > --resource-group AzureFunctionsQuickstart-rg --sku Standard_LRS --allow-blob-public-access false
Create your Function App.
az functionapp create --resource-group AzureFunctionsQuickstart-rg --consumption-plan-location < REGIO N > --runtime node --runtime-version 18 --functions-version 4 --name < APP_NAM E > --storage-account < STORAGE_NAM E >
Database Setup
Create a Redis database using Upstash Console or Upstash CLI and set UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN in your Function App’s settings.
az functionapp config appsettings set --name < APP_NAM E > --resource-group AzureFunctionsQuickstart-rg --settings UPSTASH_REDIS_REST_URL= < YOUR_UR L > UPSTASH_REDIS_REST_TOKEN= < YOUR_TOKE N >
Deploy
Take a build of your application.
Publish your application.
func azure functionapp publish < APP_NAM E >
Visit the given Invoke URL.