This tutorial uses Redis as state store for a Nuxt application. In it, we will build an application which simply increments a counter and saves & fetches the last increment time.
1 Create Nuxt.js Project#
Run this in terminal
Go to the new directory nuxtjs-with-redis and install @upstash/redis:
2 Create a Upstash Redis database#
Next, you will need an Upstash Redis database. You can follow our guide for creating a new database.
3 Set up environment variables#
Copy the .env.example file in this directory to .env
Then, set the following environment variables:
You can get the values of these env variables on the page of your Redis database.
If you are using the Vercel & Upstash integration, you may use the following environment variables:
4 Define the endpoint#
Next, we will define the endpoint which will call Redis:
5 Run#
Finally, we can run the application and call our endpoint:
If you are using our example app,
you can simply click the Increment button to run the endpoint we defined.
Otherwise, you can simply make a curl request:
When you make the request, you should see something like this:
Notes:#
- For best performance the application should run in the same region with the Redis database's region.