Setup
Install Celery
To get started, install the necessary libraries usingpip:
Database Setup
Create a Redis database using the Upstash Console. Export theUPSTASH_REDIS_HOST, UPSTASH_REDIS_PORT, and UPSTASH_REDIS_PASSWORD to your environment:
python-dotenv to load environment variables from a .env file:
.env
Example Application
Setting up Celery with Upstash Redis
tasks.py
rediss:// protocol to connect to redis over TLS and set ssl_cert_reqs=required to enforce certificate validation.
Running the Worker
Start the Celery worker to execute tasks:Using the Task
You can now use theadd task to perform background computations:
main.py