You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Custom serialization (#56)
* Changed house keeping
* Added pylint to test-requirements
* Changed packages python versions
* Changed refactored transform branch tables to private
* Changed Refactor transform into encoding/decoding
* Changed pep8 unto thyself
* Changed pylama bug, NANI
* Changed attribute to indicate it's private
* Added initial happy path test
* Changed type hinting
* Added test check we can store the result from initial to a second
* Added test that assert result from second store and encode is still expected value
* Added encryption example test
* Added tests for encrypted values
* Changed improved message during unit test failure
* Changed consistent naming
* Changed typing, type hints
* Changed both new test files are now part of coverage test run
* Added readme section for extended types
* Changed readme example to use repl
* Added defaults for custom types
* Changed updated testing and added additional example
* Changed linting change
* Added readme datetime example
* Changed, QOL
* Added allow for extending types based on method name
* Changed update docstring to latest change
RedisDict is a Python library that provides a convenient and familiar interface for interacting with Redis as if it were a Python dictionary. This simple yet powerful library enables you to manage key-value pairs in Redis using native Python syntax. It supports various data types, including strings, integers, floats, booleans, lists, and dictionaries, and includes additional utility functions for more complex use cases.
7
-
8
-
By leveraging Redis for efficient key-value storage, RedisDict allows for high-performance data management and is particularly useful for handling large datasets that may exceed local memory capacity.
6
+
RedisDict is a Python library that offers a convenient and familiar interface for interacting with Redis, treating it as if it were a Python dictionary. Its goal is to help developers write clean, Pythonic code while using Redis as a storage solution for seamless distributed computing. This simple yet powerful library utilizes Redis as a key-value store and supports various data types, including strings, integers, floats, booleans, lists, and dictionaries. Additionally, developers can extend RedisDict to work with custom objects.
9
7
8
+
The library includes utility functions for more complex use cases such as caching, batching, and more. By leveraging Redis for efficient key-value storage, RedisDict enables high-performance data management, maintaining efficiency even with large datasets and Redis instances.
10
9
11
10
## Features
12
11
@@ -17,20 +16,27 @@ By leveraging Redis for efficient key-value storage, RedisDict allows for high-p
17
16
* Efficiency and Scalability: RedisDict is designed for use with large datasets and is optimized for efficiency. It retrieves only the data needed for a particular operation, ensuring efficient memory usage and fast performance.
18
17
* Namespace Management: Provides simple and efficient namespace handling to help organize and manage data in Redis, streamlining data access and manipulation.
19
18
* Distributed Computing: With its ability to seamlessly connect to other instances or servers with access to the same Redis instance, RedisDict enables easy distributed computing.
20
-
* Custom data types: Add custom types and transformations to suit your specific needs.
19
+
* Custom data: types: Add custom types encoding/decoding to store your data types.
20
+
* Encryption: allows for storing data encrypted, while retaining the simple dictionary interface.
21
21
22
22
## Example
23
23
Redis is an exceptionally fast database when used appropriately. RedisDict leverages Redis for efficient key-value storage, enabling high-performance data management.
@@ -43,12 +49,12 @@ In Redis our example looks like this.
43
49
"str:hello world"
44
50
```
45
51
52
+
46
53
### Namespaces
47
-
Acting as an identifier for your dictionary across different systems, RedisDict employs namespaces for organized data management. When a namespace isn't specified, "main" becomes the default. Thus allowing for data organization accross systems and projects with the same redis instance.
54
+
Acting as an identifier for your dictionary across different systems, RedisDict employs namespaces for organized data management. When a namespace isn't specified, "main" becomes the default. Thus allowing for data organization across systems and projects with the same redis instance.
48
55
49
56
This approach also minimizes the risk of key collisions between different applications, preventing hard-to-debug issues. By leveraging namespaces, RedisDict ensures a cleaner and more maintainable data management experience for developers working on multiple projects.
50
57
51
-
52
58
## Advanced Features
53
59
54
60
### Expiration
@@ -81,6 +87,8 @@ with dic.expire_at(seconds):
81
87
3. Updating keys while preserving the initial timeout In certain situations, there is a need to update the value while keeping the expiration intact. This is achievable by setting the 'preserve_expiration' to true.
# Get value by key, from any instance connected to the same redis/namespace
160
170
print(dic["name"]) # Output: John Doe
161
171
162
172
# Update value by key, got a year older
@@ -209,10 +219,61 @@ print(dic["d"]) # Output: 4
209
219
For more advanced examples of RedisDict, please refer to the unit-test files in the repository. All features and functionalities are thoroughly tested in [unit tests (here)](https://github.com/Attumm/redis-dict/blob/main/tests.py#L1) Or take a look at load test for batching [load test](https://github.com/Attumm/redis-dict/blob/main/load_test.py#L1).
210
220
The unit-tests can be as used as a starting point.
211
221
222
+
### Extending Types
223
+
224
+
## Extending RedisDict with Custom Types
225
+
226
+
RedisDict supports custom type serialization. Here's how to add a new type:
227
+
228
+
229
+
```python
230
+
import json
231
+
from redis_dict import RedisDict
232
+
233
+
classPerson:
234
+
def__init__(self, name, age):
235
+
self.name = name
236
+
self.age = age
237
+
238
+
defencode(self) -> str:
239
+
return json.dumps(self.__dict__)
240
+
241
+
@classmethod
242
+
defdecode(cls, encoded_str: str) -> 'Person':
243
+
returncls(**json.loads(encoded_str))
244
+
245
+
redis_dict = RedisDict()
246
+
247
+
# Extend redis dict with the new type
248
+
redis_dict.extends_type(Person)
249
+
250
+
# RedisDict can now seamlessly handle Person instances.
For storing encrypted data values, it's possible to use extended types. Take a look at this [encrypted test](https://github.com/Attumm/redis-dict/blob/main/encrypt_tests.py).
216
277
217
278
### Tests
218
279
The RedisDict library includes a comprehensive suite of tests that ensure its correctness and resilience. The test suite covers various data types, edge cases, and error handling scenarios. It also employs the Hypothesis library for property-based testing, which provides fuzz testing to evaluate the implementation
0 commit comments