Upstash Redis
A Redis counter example that stores a hash of function invocation count per region. Find the code on GitHub.
Redis database setup#
Create a Redis database using the Upstash Console or Upstash CLI.
Select the Global type to minimize the latency from all edge locations. Copy the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN to your .env file.
You'll find them under Details > REST API > .env.
_10cp supra/functions/upstash-redis-counter/.env.example supra/functions/upstash-redis-counter/.env
Code#
Make sure you have the latest version of the Supra CLI installed.
Create a new function in your project:
_10supra functions new upstash-redis-counter
And add the code to the index.ts file:
Run locally#
_10supra start_10supra functions serve --no-verify-jwt --env-file supra/functions/upstash-redis-counter/.env
Navigate to http://localhost:54321/functions/v1/upstash-redis-counter.
Deploy#
_10supra functions deploy upstash-redis-counter --no-verify-jwt_10supra secrets set --env-file supra/functions/upstash-redis-counter/.env