https://github.com/buanzo/deadset
Python class that implements redis expiration for items
https://github.com/buanzo/deadset
python3 redis
Last synced: 6 months ago
JSON representation
Python class that implements redis expiration for items
- Host: GitHub
- URL: https://github.com/buanzo/deadset
- Owner: buanzo
- License: apache-2.0
- Created: 2017-12-19T16:40:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-31T16:04:00.000Z (over 2 years ago)
- Last Synced: 2025-03-28T01:18:28.623Z (7 months ago)
- Topics: python3, redis
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deadset
A python class that provides item level expiration functionality for redis.
The expiration collector is NOT run automagically, you need to call it. See
the example below.# Example usage
```
import random
from time import sleep
from pprint import pprint
from deadset import DeadSetq5m = DeadSet(keyname="ITEMS_DIE_HERE",
default_expire=datetime.timedelta(minutes=5))# this item we are adding _MAY_ stop existing in 5m
q5m.add_expiring_item(itemId=str(random.random()))print("UPDATES WILL BE PRINTED EVERY 60 SECONDS")
while True:
ret = q5m.expire_items()
zs = q5m.zscan()
print("Number of items deleted: {}".format(ret))
pprint(zs)
if ret > 0:
break
sleep(60)
```
# Links to inspiration sources:[TTL for a Set Member](https://stackoverflow.com/questions/17060672/ttl-for-a-set-member)
[How to expire List Items inRedis](https://quickleft.com/blog/how-to-create-and-expire-list-items-in-redis/)