From c6cb5a0277fce1b87a4b417002289c31f0ee44bc Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 29 Dec 2021 00:02:50 +0000 Subject: [PATCH] Refs #29708 -- Stopped inheriting from PickleSerializer by RedisSerializer. --- django/core/cache/backends/redis.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/django/core/cache/backends/redis.py b/django/core/cache/backends/redis.py index ec2fb06102c..f168e937379 100644 --- a/django/core/cache/backends/redis.py +++ b/django/core/cache/backends/redis.py @@ -1,31 +1,30 @@ """Redis cache backend.""" +import pickle import random import re from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache -from django.core.serializers.base import PickleSerializer from django.utils.functional import cached_property from django.utils.module_loading import import_string -class RedisSerializer(PickleSerializer): - """ - Similar to PickSerializer, except integers are serialized as native Redis - integers for better incr() and decr() atomicity. - """ +class RedisSerializer: + def __init__(self, protocol=None): + self.protocol = pickle.HIGHEST_PROTOCOL if protocol is None else protocol + def dumps(self, obj): # Only skip pickling for integers, a int subclasses as bool should be # pickled. if type(obj) is int: return obj - return super().dumps(obj) + return pickle.dumps(obj, self.protocol) def loads(self, data): try: return int(data) except ValueError: - return super().loads(data) + return pickle.loads(data) class RedisCacheClient: