mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Refs #29708 -- Stopped inheriting from PickleSerializer by RedisSerializer.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							08d8bccbf1
						
					
				
				
					commit
					c6cb5a0277
				
			
							
								
								
									
										15
									
								
								django/core/cache/backends/redis.py
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								django/core/cache/backends/redis.py
									
									
									
									
										vendored
									
									
								
							| @@ -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: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user