Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

### Breaking changes
- `BackendCommands` and `AsyncBackendCommands` are no longer decorated with `omit_exception`.
- added `omit_exception_async` to decorate async operations, instead of using `omit_exception` for both sync and async.
- `omit_exception` no longer supports async functions and generators.
- added `DecoratedBackendCommands` and `DecoratedAsyncBackendCommands` as commands decorated with `omit_exception` and `omit_exception_async`.
- `AsyncValkeyCache` and `ValkeyCache` no longer inherit from `BackendCommands` and `AsyncBackendCommands`, they inherit from `DecoratedBackendCommands` and `DecoratedAsyncBackendCommands` instead.
- stdlib `zstd` is used instead of `pyzstd` (`zstd` is the same as `pyzstd`, but since the package name are different this is counted is breaking change)

### improvement
- removed the undecorator loop from cluster client
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Install 3rd party compression

.. code-block:: console

python -m pip install django-valkey[pyzstd]
python -m pip install django-valkey[zstd] # not need since python 3.14

.. code-block:: console

Expand Down
20 changes: 13 additions & 7 deletions django_valkey/compressors/zstd.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import pyzstd

import sys
from django.conf import settings

from django_valkey.compressors.base import BaseCompressor

if sys.version_info >= (3, 14):
from compression import zstd
else:
from backports import zstd


class ZStdCompressor(BaseCompressor):
"""
Expand All @@ -19,7 +23,8 @@ class ZStdCompressor(BaseCompressor):
}

compression parameters:
to set `level_or_option` use either `CACHE_COMPRESS_LEVEL` or `COMPRESS_ZSTD_OPTIONS` in your settings.
to set `level` use `CACHE_COMPRESS_LEVEL`
to set `options` `COMPRESS_ZSTD_OPTIONS` in your settings.
if `COMPRESSION_ZSTD_OPTIONS` is set, level won't be used

to set `minimum size` set `CACHE_COMPRESS_MIN_LENGTH` in your settings, defaults to 15.
Expand All @@ -41,15 +46,16 @@ class ZStdCompressor(BaseCompressor):
decomp_zstd_dict = getattr(settings, "DECOMPRESS_ZSTD_DICT", None)

def _compress(self, value: bytes) -> bytes:
return pyzstd.compress(
return zstd.compress(
value,
level_or_option=self.options or self.level or 1,
options=self.options,
level=self.level or 1,
zstd_dict=self.zstd_dict,
)

def _decompress(self, value: bytes) -> bytes:
return pyzstd.decompress(
return zstd.decompress(
value,
zstd_dict=self.decomp_zstd_dict or self.zstd_dict,
option=self.decomp_options or self.options,
options=self.decomp_options or self.options,
)
15 changes: 10 additions & 5 deletions docs/configure/compressors.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,21 @@ compress_zlib_wbits = 15 # defaults to 15 (NOTE: only available in python 3.11

### Zstd compression

to use zstd compression you need to have the pyzstd library installed
as of `django-valkey` 0.4.0, the zstd library from python stdlib is used instead of `pyzstd`.

if you are using python 3.14 or above, you don't need to install anything,
otherwise, you need to install the `backports.zstd` library:

```shell
pip install django-valkey[pyzstd]
pip install django-valkey[zstd]
# or
pip install django-valkey[pyzstd] # this is for backwards compatibility
```

or simply
or

```shell
pip install pyzstd
pip install backports.zstd
```

then you can configure it as such:
Expand All @@ -216,4 +221,4 @@ COMPRESS_ZSTD_DICT = {...}
DECOMPRESS_ZSTD_DICT = {...} # note: if you don't set this, the above one will be used.
```

*NOTE* the values shown here are only examples and *not* best practice or anything.
*NOTE* the values shown here are only examples and *not* best practice or anything.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ lz4 = [
"lz4>=4.3.3",
]
pyzstd = [
"pyzstd>=0.16.2",
"backports.zstd>=1.0.0",
]
zstd = [
"backports.zstd>=1.0.0",
]
msgpack = [
"msgpack>=1.1.0",
Expand Down