Skip to content

Instantly share code, notes, and snippets.

@itamarhaber
Created April 19, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itamarhaber/11089937 to your computer and use it in GitHub Desktop.
Save itamarhaber/11089937 to your computer and use it in GitHub Desktop.
Kill idle Redis connections
import redis
import re
idle_max = 300
r = redis.Redis(host="localhost", port=6379, password=None)
l = r.execute_command("client", "list")
pattern = r"addr=(.*?) .*? idle=(\d*)"
regex = re.compile(pattern)
for match in regex.finditer(l):
if int(match.group(2)) > idle_max:
r.execute_command("client", "kill", match.group(1))
@itamarhaber
Copy link
Author

To use, edit and set idle_max to required value, as well as the connection properties. Once done, execute from the shell by doing:

$ python hitman.py

(and don't forget to 'sudo pip install redis' if you haven't already...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment