MultiMapWithTTL
An implementation of multimap with per-item expiration backed up by Redis.
- Documentation: https://loggi.github.io/python-multimapwithttl
- GitHub: https://github.com/loggi/python-multimapwithttl
- PyPI: https://pypi.org/project/python-multimapwithttl/
- Free software: MIT
Description
This lib is based on: https://quickleft.com/blog/how-to-create-and-expire-list-items-in-redis/ without the need for an extra job to delete old items.
Values are internally stored on Redis using Sorted Sets :
key1: { (score1, value1), (score2, value2), ... }
key2: { (score3, value3), (score4, value4), ... }
...
Where the score is the timestamp when the value was added.
We use the timestamp to filter expired values and when an insertion happens,
we opportunistically garbage collect expired values.
The key itself is set to expire through redis ttl mechanism together with the newest value. These operations result in a simulated multimap with item expiration.
You can use to keep track of values associated to keys, when the value has a notion of expiration.
>>> s = MultiMapWithTTL(redis_client, 'multimap')
>>> s.add('a', 1, 2, 3)
>>> sorted(s.get('a'))
[1, 2, 3]
>>> s.add_many([('b', (4, 5, 6)), ('c', (7, 8, 9)), ])
>>> sorted(sorted(values) for values in s.get_many('a', 'b', 'c')))
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Release files for python-multimapwithttl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python-multimapwithttl-0.1.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_multimapwithttl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.1 kB
Release files / python-multimapwithttl-0.1.0.tar.gz
| Download URL | python-multimapwithttl-0.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96ea281839b8b6bddf44befd5ec775735f7f0afbcae925bc62fe338df89bca19
|
|
BLAKE2b-256 checksum How to use checksums |
a529311c99f63bf2cafd8b8ae5723036a4804b9ea0a845d44d8fe5c8acdf60fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8
|
Release files / python_multimapwithttl-0.1.0-py3-none-any.whl
| Download URL | python_multimapwithttl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
858d5692be630ab32fcfe3573363832475fc351537e1f11607c62187865131bd
|
|
BLAKE2b-256 checksum How to use checksums |
55b7326bbd8cf6b28ef6c64ac59c8e0fd4746b1cb9ced9e4f150821249f0fe78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8
|