hello
today i made a backend to use valkey as a cache database
it’s django’s own backend, just altered to call valkey (as they have the same API)
this is the repo
i have also made a pypi package for it https://pypi.org/project/django-valkey/
one of the devs in django discord suggested that i turn it into a patch (of course with changes to fit django codebase) and add it to django itself
so i was wondering what the community thinks of it
tho i probably will need some help to adjust the test case if it were to be added to django
Hi!
Congratulations on making a new package. It looks like it fits a need well.
Redis has had a lot of forks, especially since the license change. Valkey is definitely one of the more interesting ones, given its higher performance. But I have also seen Redict touted as “the new redis”. Most don’t have their own client libraries either, as far as I understand.
I think if we are going to do anything in Django at this point, it should be to make it easier for packages like yours to exist, swapping out the client library or other details as necessary.
I would note that you have a lot of duplication with the existing Redis backend and could reuse that better. For example, your ValkeyCacheClient
could probably do this:
class ValkeyCacheClient(RedisCacheClient):
def __init__(
self,
servers,
serializer=None,
pool_class=None,
parser_class=None,
**options,
):
# Don’t call super(), as that imports `redis`
import valkey
self._lib = valkey
self._servers = servers
self._pools = {}
self._client = self._lib.Valkey
if isinstance(pool_class, str):
pool_class = import_string(pool_class)
self._pool_class = pool_class or self._lib.ConnectionPool
if isinstance(serializer, str):
serializer = import_string(serializer)
if callable(serializer):
serializer = serializer()
self._serializer = serializer or ValkeySerializer()
if isinstance(parser_class, str):
parser_class = import_string(parser_class)
parser_class = parser_class or self._lib.connection.DefaultParser
self._pool_options = {"parser_class": parser_class, **options}
Perhaps we could patch Django to fix this annoying evasion of `super(), for example.
If a clear Redis “winner” emerges with popular community support, we could consider supporting it. But for now, third-party packages are a great solution for supporting Redis alternatives with other client libraries.
What do you think?
Hi
Thanks for the feedback!
I actually hadn’t heard of other redis forks, saw valkey on github and read somewhere that redis contributors are behind it so figured it would be the go to tool.
The reason for duplication was that I’m planning on expanding the project to look more like the django-redis package, and thought having explicit code at the start and refactoring later would save me from having ten files open at the same time.
In any case, I’m fine with any decision the DSF makes on this, I’d be more than happy to package the code as a 3rd party or send a patch to the djangoproject.