Summary
RedisType instances (RedisStr, RedisInt, RedisFloat, RedisBytes, RedisList, RedisDict) should be picklable so they can be used as values within arbitrary container types like dict[str, Any], list[Any], or any other serialization context that relies on pickle.
Currently, pickling a RedisType instance fails because it holds a _base_model_link reference to the parent AtomicRedisModel, which in turn contains unpicklable Redis client/connection objects.
Use Cases
- Storing RedisType values inside a
dict[str, Any] field that gets serialized via pickle
- Passing RedisType instances across process boundaries (e.g., multiprocessing)
- Any generic serialization workflow that expects values to be picklable
Features / Details
- Implement
__getstate__ / __setstate__ on BaseRedisType to handle pickling
- Exclude unpicklable references (
_base_model_link and transitive Redis client/connection objects) during __getstate__
- Restore or reset state appropriately in
__setstate__
- Handle container types (RedisList, RedisDict) which recursively hold child RedisType items with parent references
- Preserve the actual value (the underlying
str, int, float, bytes, list, dict) through the pickle round-trip
Implementation Considerations
_base_model_link creates circular references and holds unpicklable Redis connections — it must be excluded or replaced during pickling
- After unpickling,
_base_model_link will be None — the unpickled instance is a "detached" value, no longer connected to Redis
- Container types (RedisList, RedisDict) need to recursively handle child items'
_base_model_link references
- Context-tracking fields like
_redis_updated and _last_action_groups should either be preserved or reset to defaults on unpickling
List tasks
Summary
RedisType instances (RedisStr, RedisInt, RedisFloat, RedisBytes, RedisList, RedisDict) should be picklable so they can be used as values within arbitrary container types like
dict[str, Any],list[Any], or any other serialization context that relies on pickle.Currently, pickling a RedisType instance fails because it holds a
_base_model_linkreference to the parentAtomicRedisModel, which in turn contains unpicklable Redis client/connection objects.Use Cases
dict[str, Any]field that gets serialized via pickleFeatures / Details
__getstate__/__setstate__onBaseRedisTypeto handle pickling_base_model_linkand transitive Redis client/connection objects) during__getstate____setstate__str,int,float,bytes,list,dict) through the pickle round-tripImplementation Considerations
_base_model_linkcreates circular references and holds unpicklable Redis connections — it must be excluded or replaced during pickling_base_model_linkwill beNone— the unpickled instance is a "detached" value, no longer connected to Redis_base_model_linkreferences_redis_updatedand_last_action_groupsshould either be preserved or reset to defaults on unpicklingList tasks
__getstate__and__setstate__onBaseRedisTypeto exclude_base_model_linkand related unpicklable objectsRedisListandRedisDictto handle recursive child field referencesdict[str, Any]andlist[Any]containers