redis package.
At a glance
This guide adds to the application from Deploy a Django application:Environment variables
The internal connection also adds
REDIS_HOST, REDIS_PORT and REDIS_PASSWORD, which the project doesn’t read. The deploy guide lists the other variables.
Before you begin
- A Django project deployed on Sevalla, as in Deploy Django.
Create a Redis database
1
Create the database
In the sidebar, click Databases, then click Create database. Under Database, choose Redis, or Valkey: the code in this guide works with both. Enter
storefront-redis as the Display name, choose the same Data center as the application and a Size, then click Create database.2
Connect it to the application
In the sidebar, click Applications, then click the application. Click the Networking tab. Under Connected services, click Add internal connection. Choose
storefront-redis as the Service, turn on Add environment variables to the application, and click Add internal connection. Sevalla adds REDIS_HOST, REDIS_PORT, REDIS_PASSWORD and REDIS_URL. See Connect an application.

Configure the cache
Install redis-py and updaterequirements.txt:
storefront/settings.py, use Django’s Redis backend with the URL from the internal connection:
storefront/settings.py
cache_page, template fragment caching ({% cache %}) and the low-level API (django.core.cache.cache).
Cache a view
Cache a view’s response for 2 minutes withcache_page:
storefront/views.py
storefront/urls.py
requirements.txt included: Ingot installs redis on the next build. If Auto-deploy is off, click Deploy now on the application’s Overview tab.
Verify
When the deployment’s status is Deployed, request the page twice, with your application’s domain:Generated at 16:08:48, and carry Cache-Control: max-age=120. After 2 minutes, the next request shows a new time. To see both in one run:
execProcessCommandV3), with APP_ID and WEB_ID from Deploy with the API:
cache_page stores keys whose names start with :1:views.decorators.cache.cache_page. See Database studio.
Control the CDN and edge cache
Sevalla can also cache responses at Cloudflare’s edge, in front of the application. Turn on the CDN and edge caching on the application’s Networking tab; see CDN and edge caching.- The CDN caches static files by file extension, such as
.css,.jsand images. WhiteNoise’s hashed file names make them safe to cache for a long time. - Edge caching caches pages and other responses too. It caches only
GETrequests, skips requests with anAuthorizationheader, and doesn’t store responses that set a cookie, such as pages that start a session or set the CSRF cookie. - When a response has no
Cache-Controlheader, Sevalla adds one. With edge caching on, a200response without its own header can stay cached for up to 30 days, unless a deployment or a purge clears the cache first. See Control caching from your application.
Cache-Control on every view. never_cache keeps a page out of every cache, and cache_control sets how long it may be kept:
storefront/views.py
never_cache. To check what a page sends, run curl -sI https://storefront-x7k2m.sevalla.app/catalog/ and read the Cache-Control header.
Deploy with the API
This sequence adds the Redis database to the application from Deploy with the API and continues in its shell, withAPI, CLUSTER_ID, DB1_ID and APP_ID set. Push the code changes from Configure the cache and Cache a view first. Each step names the CLI command and the Sevalla MCP server tool that do the same.
1
Look up the Redis version
List database versions (CLI:
listDatabaseVersionsV3) returns the versions the location offers, oldest first. Save the newest:sevalla resources db-versions --cluster "$CLUSTER_ID" --type redis. MCP: not needed, create_database takes the newest version by default.2
Create the database
Create database (CLI:
createDatabaseV3). You choose the password, and the API never returns it, so keep it for the connection URL:sevalla databases create --name storefront-redis --type redis --db-version "$REDIS_VERSION" --cluster "$CLUSTER_ID" --resource-type "$DB1_ID" --db-name storefront --db-password "$REDIS_PASSWORD". MCP: create_database with type: "redis"; with connect_to_application_id and env_var_name: "REDIS_URL", it also does the internal connection and adds REDIS_URL.3
Wait for the database
Get database (CLI:
getDatabaseV3) shows status ready when the database is up, with its internal hostname and port:sevalla databases get "$REDIS_ID". MCP: get_database.4
Connect the database
Create internal connection (The API adds no environment variables; the next step adds them. CLI:
createApplicationInternalConnectionV3):sevalla apps internal-connections create "$APP_ID" --target-id "$REDIS_ID" --target-type database. MCP: sevalla_api_create with createApplicationInternalConnectionV3 and the same body.5
Add the environment variables
Create environment variable (CLI:
createEnvironmentVariableV3), once per variable, with the names and format of the dashboard’s internal connection:sevalla apps env-vars create "$APP_ID" --key REDIS_URL --value "redis://:$REDIS_PASSWORD@$REDIS_HOST:$REDIS_PORT/0", once per variable. MCP: set_environment_variables.6
Deploy
Trigger deployment (CLI:
triggerDeploymentV3) deploys the latest commit with the Redis variables. With Auto-deploy on, the push already started a deployment, without them; this one queues behind it:sevalla apps deployments trigger "$APP_ID". MCP: trigger_deployment.7
Wait for the deployment
Get deployment (CLI:
getDeploymentV3) reports the status, which ends as success, failed, cancelled or skipped. The loop keeps polling through a failed request, for up to 30 minutes:sevalla apps deployments get "$DEPLOYMENT_ID" --app-id "$APP_ID". MCP: get_deployment.