# adding support for valkey (Redis alternetive)

**URL:** <https://forum.djangoproject.com/t/adding-support-for-valkey-redis-alternetive/34391>\
**Category:** Django Internals\
**Created:** [September 1, 2024, 4:56pm UTC](https://forum.djangoproject.com/t/adding-support-for-valkey-redis-alternetive/34391 "2024-09-01T16:56:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amirreza8002](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amirreza8002/32/27683_2.png) [@amirreza8002](https://forum.djangoproject.com/u/amirreza8002)\
**Post date:** [September 1, 2024, 4:56pm UTC](https://forum.djangoproject.com/t/adding-support-for-valkey-redis-alternetive/34391/1 "2024-09-01T16:56:22Z")

</div>

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](https://github.com/amirreza8002/django-valkey)  
i have also made a pypi package for it [https://pypi.org/project/django-valkey/](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

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [September 2, 2024, 9:19pm UTC](https://forum.djangoproject.com/t/adding-support-for-valkey-redis-alternetive/34391/2 "2024-09-02T21:19:10Z")

</div>

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”](https://andrewkelley.me/post/redis-renamed-to-redict.html). 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:

```python
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?

---

<div class="post-metadata">

**Author:** ![amirreza8002](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/amirreza8002/32/27683_2.png) [@amirreza8002](https://forum.djangoproject.com/u/amirreza8002)\
**Post date:** [September 2, 2024, 9:58pm UTC](https://forum.djangoproject.com/t/adding-support-for-valkey-redis-alternetive/34391/3 "2024-09-02T21:58:02Z")

</div>

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.
