deadset

Deadset is a Python 3 module that implements expiration for Redis Keys items.


Keywords
python3, redis
License
Apache-2.0
Install
pip install deadset==0.2

Documentation

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 DeadSet

q5m = 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 How to expire List Items inRedis