redis-dict 3.0.0__py3-none-any.whl → 3.1.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- redis_dict/core.py +26 -28
- redis_dict/type_management.py +7 -4
- {redis_dict-3.0.0.dist-info → redis_dict-3.1.0.dist-info}/METADATA +2 -2
- redis_dict-3.1.0.dist-info/RECORD +9 -0
- redis_dict-3.0.0.dist-info/RECORD +0 -9
- {redis_dict-3.0.0.dist-info → redis_dict-3.1.0.dist-info}/LICENSE +0 -0
- {redis_dict-3.0.0.dist-info → redis_dict-3.1.0.dist-info}/WHEEL +0 -0
- {redis_dict-3.0.0.dist-info → redis_dict-3.1.0.dist-info}/top_level.txt +0 -0
redis_dict/core.py
CHANGED
@@ -35,13 +35,6 @@ class RedisDict:
|
|
35
35
|
This functionality enables various use cases, such as managing encrypted data in Redis,
|
36
36
|
To implement this, simply create and register your custom encoding and decoding functions.
|
37
37
|
By delegating serialization to redis-dict, reduce complexity and have simple code in the codebase.
|
38
|
-
|
39
|
-
Attributes:
|
40
|
-
decoding_registry (Dict[str, DecodeFuncType]): Mapping of decoding transformation functions based on type
|
41
|
-
encoding_registry (Dict[str, EncodeFuncType]): Mapping of encoding transformation functions based on type
|
42
|
-
namespace (str): A string used as a prefix for Redis keys to separate data in different namespaces.
|
43
|
-
expire (Union[int, None]): An optional expiration time for keys, in seconds.
|
44
|
-
|
45
38
|
"""
|
46
39
|
|
47
40
|
encoding_registry: EncodeType = enc_reg
|
@@ -53,7 +46,8 @@ class RedisDict:
|
|
53
46
|
preserve_expiration: Optional[bool] = False,
|
54
47
|
redis: "Optional[StrictRedis[Any]]" = None,
|
55
48
|
**redis_kwargs: Any) -> None:
|
56
|
-
"""
|
49
|
+
"""
|
50
|
+
Initialize a RedisDict instance.
|
57
51
|
|
58
52
|
Init the RedisDict instance.
|
59
53
|
|
@@ -220,7 +214,8 @@ class RedisDict:
|
|
220
214
|
encoding_method_name: Optional[str] = None,
|
221
215
|
decoding_method_name: Optional[str] = None,
|
222
216
|
) -> None:
|
223
|
-
"""
|
217
|
+
"""
|
218
|
+
Extend RedisDict to support a custom type in the encode/decode mapping.
|
224
219
|
|
225
220
|
This method enables serialization of instances based on their type,
|
226
221
|
allowing for custom types, specialized storage formats, and more.
|
@@ -247,19 +242,19 @@ class RedisDict:
|
|
247
242
|
attributes of the RedisDict instance
|
248
243
|
|
249
244
|
Example:
|
250
|
-
class Person:
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
redis_dict.extends_type(Person)
|
245
|
+
>>> class Person:
|
246
|
+
... def __init__(self, name, age):
|
247
|
+
... self.name = name
|
248
|
+
... self.age = age
|
249
|
+
...
|
250
|
+
... def encode(self) -> str:
|
251
|
+
... return json.dumps(self.__dict__)
|
252
|
+
...
|
253
|
+
... @classmethod
|
254
|
+
... def decode(cls, encoded_str: str) -> 'Person':
|
255
|
+
... return cls(**json.loads(encoded_str))
|
256
|
+
...
|
257
|
+
>>> redis_dict.extends_type(Person)
|
263
258
|
|
264
259
|
Args:
|
265
260
|
class_type (type): The class `__name__` will become the key for the encoding and decoding functions.
|
@@ -409,8 +404,8 @@ class RedisDict:
|
|
409
404
|
return str(self.to_dict())
|
410
405
|
|
411
406
|
def __or__(self, other: Dict[str, Any]) -> Dict[str, Any]:
|
412
|
-
"""
|
413
|
-
|
407
|
+
"""Implement the | operator (dict union).
|
408
|
+
|
414
409
|
Returns a new dictionary with items from both dictionaries.
|
415
410
|
|
416
411
|
Args:
|
@@ -432,7 +427,8 @@ class RedisDict:
|
|
432
427
|
|
433
428
|
def __ror__(self, other: Dict[str, Any]) -> Dict[str, Any]:
|
434
429
|
"""
|
435
|
-
|
430
|
+
Implement the reverse | operator.
|
431
|
+
|
436
432
|
Called when RedisDict is on the right side of |.
|
437
433
|
|
438
434
|
Args:
|
@@ -454,7 +450,8 @@ class RedisDict:
|
|
454
450
|
|
455
451
|
def __ior__(self, other: Dict[str, Any]) -> 'RedisDict':
|
456
452
|
"""
|
457
|
-
|
453
|
+
Implement the |= operator (in-place union).
|
454
|
+
|
458
455
|
Modifies the current dictionary by adding items from other.
|
459
456
|
|
460
457
|
Args:
|
@@ -475,7 +472,7 @@ class RedisDict:
|
|
475
472
|
@classmethod
|
476
473
|
def __class_getitem__(cls: Type['RedisDict'], key: Any) -> Type['RedisDict']:
|
477
474
|
"""
|
478
|
-
|
475
|
+
Enable type hinting support like RedisDict[str, Any].
|
479
476
|
|
480
477
|
Args:
|
481
478
|
key (Any): The type parameter(s) used in the type hint.
|
@@ -487,7 +484,8 @@ class RedisDict:
|
|
487
484
|
|
488
485
|
def __reversed__(self) -> Iterator[str]:
|
489
486
|
"""
|
490
|
-
|
487
|
+
Implement reversed() built-in.
|
488
|
+
|
491
489
|
Returns an iterator over dictionary keys in reverse insertion order.
|
492
490
|
|
493
491
|
Warning:
|
redis_dict/type_management.py
CHANGED
@@ -143,7 +143,8 @@ encoding_registry: EncodeType = {
|
|
143
143
|
|
144
144
|
|
145
145
|
class RedisDictJSONEncoder(json.JSONEncoder):
|
146
|
-
"""
|
146
|
+
"""
|
147
|
+
Extends JSON encoding capabilities by reusing RedisDict type conversion.
|
147
148
|
|
148
149
|
Uses existing decoding_registry to know which types to handle specially and
|
149
150
|
encoding_registry (falls back to str) for converting to JSON-compatible formats.
|
@@ -157,11 +158,11 @@ class RedisDictJSONEncoder(json.JSONEncoder):
|
|
157
158
|
}
|
158
159
|
|
159
160
|
Notes:
|
160
|
-
|
161
161
|
Uses decoding_registry (containing all supported types) to check if type
|
162
162
|
needs special handling. For encoding, defaults to str() if no encoder exists
|
163
163
|
in encoding_registry.
|
164
164
|
"""
|
165
|
+
|
165
166
|
def default(self, o: Any) -> Any:
|
166
167
|
"""Overwrite default from json encoder.
|
167
168
|
|
@@ -187,13 +188,15 @@ class RedisDictJSONEncoder(json.JSONEncoder):
|
|
187
188
|
|
188
189
|
|
189
190
|
class RedisDictJSONDecoder(json.JSONDecoder):
|
190
|
-
"""
|
191
|
+
"""
|
192
|
+
JSON decoder leveraging RedisDict existing type conversion system.
|
191
193
|
|
192
194
|
Works with RedisDictJSONEncoder to reconstruct Python objects from JSON using
|
193
195
|
RedisDict decoding_registry.
|
194
196
|
|
195
197
|
Still needs work but allows for more types than without.
|
196
198
|
"""
|
199
|
+
|
197
200
|
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
198
201
|
"""
|
199
202
|
Overwrite the __init__ method from JSON decoder.
|
@@ -254,7 +257,7 @@ def _default_decoder(x: str) -> str:
|
|
254
257
|
|
255
258
|
def _default_encoder(x: Any) -> str:
|
256
259
|
"""
|
257
|
-
|
260
|
+
Take x and returns the result str of the object.
|
258
261
|
|
259
262
|
Args:
|
260
263
|
x (Any): The input object
|
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: redis-dict
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.1.0
|
4
4
|
Summary: Dictionary with Redis as storage backend
|
5
5
|
Author-email: Melvin Bijman <bijman.m.m@gmail.com>
|
6
6
|
License: MIT
|
7
7
|
Project-URL: Homepage, https://github.com/Attumm/redisdict
|
8
|
-
Project-URL: Documentation, https://github.
|
8
|
+
Project-URL: Documentation, https://attumm.github.io/redis-dict/
|
9
9
|
Project-URL: Repository, https://github.com/Attumm/redisdict.git
|
10
10
|
Project-URL: Changelog, https://github.com/Attumm/redisdict/releases
|
11
11
|
Keywords: redis,python,dictionary,dict,key-value,database,caching,distributed-computing,dictionary-interface,large-datasets,scientific-computing,data-persistence,high-performance,scalable,pipelining,batching,big-data,data-types,distributed-algorithms,encryption,data-management
|
@@ -0,0 +1,9 @@
|
|
1
|
+
redis_dict/__init__.py,sha256=fksonUr5DetzwFDEkT7lpmAaV3Jhmp2IQ12t62LwFb4,476
|
2
|
+
redis_dict/core.py,sha256=ej7_EfkPIIb0gH_Ndpeue4i-WsNFGuw0dV6fNm-drzY,34352
|
3
|
+
redis_dict/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
redis_dict/type_management.py,sha256=ruyqswKqfte_G-ClTlV6ZuTmrTVkSsHFCy9LEdgblac,7700
|
5
|
+
redis_dict-3.1.0.dist-info/LICENSE,sha256=-QiLwYznh_vNUSz337k0faP9Jl0dgtCIHVZ39Uyl6cA,1070
|
6
|
+
redis_dict-3.1.0.dist-info/METADATA,sha256=wq3vcKRqTgUllyhm8oEogx9ikHCa6UT4kLNw86bfm3c,16867
|
7
|
+
redis_dict-3.1.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
8
|
+
redis_dict-3.1.0.dist-info/top_level.txt,sha256=Wyp5Xvq_imoxvu-c-Le1rbTZ3pYM5BF440H9YAcgBZ8,11
|
9
|
+
redis_dict-3.1.0.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
redis_dict/__init__.py,sha256=fksonUr5DetzwFDEkT7lpmAaV3Jhmp2IQ12t62LwFb4,476
|
2
|
-
redis_dict/core.py,sha256=iLVTzpR4HmMPqcgZQWMgdAgwRepLEhTbdxP-tfA13ts,34698
|
3
|
-
redis_dict/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
-
redis_dict/type_management.py,sha256=U3aP_EtHByApRdHvpr-zSOjok6r9BVZ0g3YnpVCVt8Y,7690
|
5
|
-
redis_dict-3.0.0.dist-info/LICENSE,sha256=-QiLwYznh_vNUSz337k0faP9Jl0dgtCIHVZ39Uyl6cA,1070
|
6
|
-
redis_dict-3.0.0.dist-info/METADATA,sha256=8Zn6a75THLjxiCGfRdFuz675RwSsLrBf0JQE8fH-Kfo,16873
|
7
|
-
redis_dict-3.0.0.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
8
|
-
redis_dict-3.0.0.dist-info/top_level.txt,sha256=Wyp5Xvq_imoxvu-c-Le1rbTZ3pYM5BF440H9YAcgBZ8,11
|
9
|
-
redis_dict-3.0.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|