Created
July 17, 2023 11:48
-
-
Save polsala/bb08983a01a8a9d308021b8a772e32a2 to your computer and use it in GitHub Desktop.
Clean not used redis keys since x seconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_idle_redis_keys(redis_host='192.168.0.4', redis_port=6379, db=0, startswithkey='rq', idletime=604800): | |
import redis | |
from tqdm import tqdm | |
r = redis.StrictRedis(host=redis_host, port=redis_port, db=db) | |
for key in tqdm(r.scan_iter("*")): | |
idle = r.object("idletime", key) | |
# idle time is in seconds. | |
if idle > idletime and key.startswith(startswithkey): | |
print("Deleting {}".format(key)) | |
r.delete(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment