Skip to content

Instantly share code, notes, and snippets.

@dfmcvn
Created August 24, 2018 11:10
Show Gist options
  • Save dfmcvn/829640deb12e742de6534e2e4b8169bb to your computer and use it in GitHub Desktop.
Save dfmcvn/829640deb12e742de6534e2e4b8169bb to your computer and use it in GitHub Desktop.
Python script: delete all Redis keys older than 6 hours
# 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