Migrating your Python Applications from Redis®* to Valkey™
You can quickly update your Python applications with Valkey™, the drop-in Redis®* replacement.
Earlier this year, the team behind Redis®* made the decision to change their license from BSD to a proprietary license in combination with the SSPL v1. While licensing changes can be confusing, one solution is to migrate to a new platform that meets your licensing preferences.
Meet Valkey™, an open-source in memory data-store that was designed to be a drop-in replacement for Redis. The development team's goal is to make it easy to take your existing Redis implementation and replace it with Valkey without having to make a large amount of changes to configuration. Your biggest change will be using a Valkey-powered key
For Python developers we often use Redis in a transparent way. Like a task queue using Celery or a simple keyvalkey
client and change your imports from redis
to valkey
.
That being said, we don’t know the plans for Redis after their licensing change so this guide will walk you through the steps of pointing your cache systems from Redis to Valkey. While this means we need to change a few more namespaces, Valkey has made it as simple as possible to make these changes quickly and confidently.
Install the Valkey Python package
The valkey Python package is available via PyPI and can be downloaded and installed using pip or any popular Python package manager.
pip install valkey
The Valkey Python Package is a fork from the last open-source version of the redis Python package which means you can install valkey[hiredis]
to use the compiled response parser from the hiredis package.
Importing and using the Valkey package
For convenience, if you were using Redis version 7.0 or lower, you only need to change your import and you can continue to use the Redis class which is still available in Valkey. To do so only replace the import from redis to from valkey. You will need to also change the path to your new Service URI.
Look at how similar the redis.py connection is compared to the valkey connection is.
Here is the Redis connection file.
from redis import Redis redis_connection = Redis.from_url( "rediss://<AIVEN_FOR_CACHING_SERVICE_URI>" decode_responses=True, )
Here is the Valkey connection file.
from valkey import Redis # change `rediss://` to `valkeys://` valkey_connection = Redis.from_url( "valkeys://<AIVEN_FOR_CACHING_SERVICE_URI>" decode_responses=True, )
Keep in mind the developers of Valkey cannot ensure that newer versions of Redis will be implemented in the same manner and the two products may deviate in development. That is why it is recommended you use the Valkey
object inside of the package instead. Everything from that point should be the same as the Redis class object from version 7. This means all your set, get, query, and all commands that were exposed to the Redis package will be identical.
>>> from valkey import Valkey >>> valkey_connection = Valkey.from_url( "valkeys://<AIVEN_FOR_CACHING_SERVICE_URI>" decode_responses=True, ) # You will still have access to all of the endpoints >>> valkey.set("memstore", "valkey") # same for hget/hset, etc >>> valkey.get("memstore") "valkey"
Aiven for Valkey is available across our many cloud providers and regions with backup and performance tiers to meet your needs.
Another Redis alternative supported by Valkey Python is Aiven for Dragonfly which supports for over 1TB of data per instance, processing over 500,000 requests per second, JSON and Vector Support for AI, compatibility with memcached, and more.