Deployment
Redis & caching

Use Valkey With Django for Caching, Sessions, and Celery

Use Valkey, the open-source Redis fork, with Django: connect Django’s Redis cache backend or django-valkey, run Celery and Channels against it, migrate from Redis with replication or snapshots, and use managed Valkey on AWS, Google Cloud, and DigitalOcean.

Problem statement

After Redis changed its license in 2024, the Linux Foundation's Valkey fork became the default in-memory store on several clouds and distributions: AWS ElastiCache and MemoryDB offer it at lower prices, Google Memorystore and DigitalOcean provide managed Valkey, and many Linux distributions package it. You want to know whether Django, Celery, and Channels work with it unchanged, and how to move an existing Redis setup over.

Django on ValkeyValkey serverRedis-compatibleCache backendredis:// URLCelery brokersame protocolChannels layersame clientValkey speaks the Redis protocol, so existing clients and URLs keep working.
  1. Valkey is protocol-compatible with Redis 7.2, so Django's built-in RedisCache, django-redis, Celery, and channels-redis work with a redis:// or rediss:// URL.
  2. Point REDIS_URL at the Valkey endpoint; no code changes are needed.
  3. Optionally use the django-valkey package and the valkey Python client if you prefer Valkey-native naming.
  4. Migrate with replication (Valkey as a replica of Redis, then promote) or by restoring an RDB snapshot.
  5. On managed clouds, choose the Valkey engine for new clusters; settings such as eviction policy and persistence carry over.

Step-by-step solution

1. Connect Django's cache

CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.redis.RedisCache",
        "LOCATION": os.environ["VALKEY_URL"],   # redis://valkey.internal:6379/1
        "KEY_PREFIX": "shop",
        "TIMEOUT": 300,
    }
}
SESSION_ENGINE = "django.contrib.sessions.backends.cache"

The redis-py client used by Django connects to Valkey without changes. django-redis works the same way if you rely on its extra features such as delete_pattern or compression.

2. Celery and Channels

CELERY_BROKER_URL = os.environ["VALKEY_URL"].rsplit("/", 1)[0] + "/0"
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {"hosts": [os.environ["VALKEY_URL"]]},
    }
}

Celery's Redis transport and channels-redis use standard commands (lists, pub/sub, Lua scripts) that Valkey implements.

does it work unchanged?Works with ValkeyChange neededDjango RedisCacheyesURL onlydjango-redisyesURL onlyCelery Redis transportyesURL onlychannels-redisyesURL onlydjango-rqyesURL onlyClients talk the Redis protocol, which Valkey implementsdjango-deployment.com
Test new Valkey-only features separately; they are not part of the Redis protocol.

3. Optional: django-valkey

The django-valkey package provides a cache backend built on the valkey client (a fork of redis-py), with the same feature set as django-redis:

CACHES = {
    "default": {
        "BACKEND": "django_valkey.cache.ValkeyCache",
        "LOCATION": "valkey://valkey.internal:6379/1",
    }
}

This is a naming and maintenance preference; the built-in Redis backend remains a fine choice.

4. Migrate from Redis

For a self-hosted Redis, the least disruptive path is replication:

# on the new Valkey server
valkey-cli REPLICAOF redis-old.internal 6379
valkey-cli INFO replication     # wait for master_link_status:up and sync done
valkey-cli REPLICAOF NO ONE     # promote

Switch REDIS_URL to the Valkey host, restart web and workers, and stop the old Redis. For a cache-only instance, you can simply point the app at an empty Valkey and let it warm up. On ElastiCache, AWS supports upgrading a Redis OSS cluster to the Valkey engine in place.

5. Configure the server

Valkey reads the same configuration directives as Redis. Keep the settings that matter for Django:

maxmemory 1gb
maxmemory-policy allkeys-lru      # for a pure cache
appendonly yes                     # for Celery broker data
requirepass ...

Use separate instances or at least separate databases for cache and broker, since they need different eviction and persistence settings.

replication-based cutover1Start Valkey as replicaREPLICAOF old Redis2Wait for full syncINFO replication3Promote ValkeyREPLICAOF NO ONE4Switch REDIS_URLrestart web, workers5Retire old Redisafter checksCelery queues and sessions survive because data is replicated firstdjango-deployment.com
For a disposable cache, pointing at an empty Valkey is enough.

Explanation

Valkey forked from Redis 7.2.4, the last version under the BSD license, and keeps wire-protocol compatibility. Clients identify themselves with the same handshake and send the same commands, so the Django and Celery ecosystems see no difference. Cloud providers adopted it for licensing reasons and often price it below their Redis offerings. Newer Valkey releases add performance improvements and features of their own, while staying compatible for the commands Django tools use.

Edge cases / notes

  • Redis 8 features. Commands added in Redis after the fork may not exist in Valkey; Django tools do not depend on them.
  • Modules. RedisJSON, RediSearch, and other Redis Stack modules are not part of Valkey; Valkey has its own module ecosystem.
  • Version reporting. Some monitoring tools check redis_version in INFO; Valkey reports compatible fields.

Next steps

FAQ

Does Django support Valkey?

Yes, through its Redis cache backend, because Valkey implements the Redis protocol.

Do I need to change my code to switch to Valkey?

No. Change the connection URL and restart processes.

Is Valkey faster than Redis?

Recent Valkey releases include multithreaded I/O improvements; for typical Django caching, both are far faster than the database.

Can Celery use Valkey as a broker?

Yes, with the Redis transport and a redis:// URL pointing at Valkey.

Keep going