diff --git a/django/core/cache/backends/redis.py b/django/core/cache/backends/redis.py index eda8ac9457..bbf070a375 100644 --- a/django/core/cache/backends/redis.py +++ b/django/core/cache/backends/redis.py @@ -14,8 +14,9 @@ class RedisSerializer: 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. + # For better incr() and decr() atomicity, don't pickle integers. + # Using type() rather than isinstance() matches only integers and not + # subclasses like bool. if type(obj) is int: return obj return pickle.dumps(obj, self.protocol)