Refs #29708 -- Stopped inheriting from PickleSerializer by RedisSerializer.

This commit is contained in:
Adam Johnson 2021-12-29 00:02:50 +00:00 committed by Mariusz Felisiak
parent 08d8bccbf1
commit c6cb5a0277
1 changed files with 7 additions and 8 deletions

View File

@ -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: