Created
August 24, 2018 11:10
-
-
Save dfmcvn/829640deb12e742de6534e2e4b8169bb to your computer and use it in GitHub Desktop.
Python script: delete all Redis keys older than 6 hours
This file contains 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
# pip install redis | |
# python purge_redis_expired.py | |
#!/usr/bin/env python | |
import redis | |
r = redis.StrictRedis(host='localhost', port=6379, db=0) | |
for key in r.scan_iter("*"): | |
idle = r.object("idletime", key) | |
# idle time is in seconds. This is 6h | |
if idle > 21600: | |
r.delete(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment