UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
to your environment:
python-dotenv
to load environment variables from your .env
file.
myproject/settings.py
, add your new app (myapp
) to the INSTALLED_APPS
list.
myapp/views.py
, add the following:
myproject/urls.py
, connect the view to a URL pattern:
http://127.0.0.1:8000/
in your browser, and the counter will increment with each page refresh.
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
. The Redis.from_env()
method initializes this connection.
index
view, we increment the counter
key each time the homepage is accessed. If the key doesn’t exist, Redis creates it and starts counting from 1.