-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e562b5c
commit 1d9c517
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import gzip | ||
|
||
from ..exceptions import CompressorError | ||
from .base import BaseCompressor | ||
|
||
|
||
class GzipCompressor(BaseCompressor): | ||
min_length = 15 | ||
|
||
def compress(self, value: bytes) -> bytes: | ||
if len(value) > self.min_length: | ||
return gzip.compress(value) | ||
return value | ||
|
||
def decompress(self, value: bytes) -> bytes: | ||
try: | ||
return gzip.decompress(value) | ||
except gzip.BadGzipFile as e: | ||
raise CompressorError(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
SECRET_KEY = "django_tests_secret_key" | ||
|
||
CACHES = { | ||
"default": { | ||
"BACKEND": "django_redis.cache.RedisCache", | ||
"LOCATION": ["redis://127.0.0.1:6379?db=1", "redis://127.0.0.1:6379?db=1"], | ||
"OPTIONS": { | ||
"CLIENT_CLASS": "django_redis.client.DefaultClient", | ||
"COMPRESSOR": "django_redis.compressors.gzip.GzipCompressor", | ||
}, | ||
}, | ||
"doesnotexist": { | ||
"BACKEND": "django_redis.cache.RedisCache", | ||
"LOCATION": "redis://127.0.0.1:56379?db=1", | ||
"OPTIONS": { | ||
"CLIENT_CLASS": "django_redis.client.DefaultClient", | ||
"COMPRESSOR": "django_redis.compressors.gzip.GzipCompressor", | ||
}, | ||
}, | ||
"sample": { | ||
"BACKEND": "django_redis.cache.RedisCache", | ||
"LOCATION": "redis://127.0.0.1:6379?db=1,redis://127.0.0.1:6379?db=1", | ||
"OPTIONS": { | ||
"CLIENT_CLASS": "django_redis.client.DefaultClient", | ||
"COMPRESSOR": "django_redis.compressors.gzip.GzipCompressor", | ||
}, | ||
}, | ||
"with_prefix": { | ||
"BACKEND": "django_redis.cache.RedisCache", | ||
"LOCATION": "redis://127.0.0.1:6379?db=1", | ||
"OPTIONS": { | ||
"CLIENT_CLASS": "django_redis.client.DefaultClient", | ||
"COMPRESSOR": "django_redis.compressors.gzip.GzipCompressor", | ||
}, | ||
"KEY_PREFIX": "test-prefix", | ||
}, | ||
} | ||
|
||
INSTALLED_APPS = ["django.contrib.sessions"] | ||
|
||
USE_TZ = False |