Skip to content

Instantly share code, notes, and snippets.

@murarisumit
Created March 31, 2018 05:24
Show Gist options
  • Save murarisumit/8538551ea70d6744c30f73829efdca45 to your computer and use it in GitHub Desktop.
Save murarisumit/8538551ea70d6744c30f73829efdca45 to your computer and use it in GitHub Desktop.
KIll redis idle connection
import redis
import re
idle_max = 300
r = redis.Redis(host="localhost", port=6379, password=None)
cl = r.execute_command("client", "list")
pattern = r"addr=(.*?) .*? idle=(\d*)"
regex = re.compile(pattern)
for match in regex.finditer(cl):
if int(match.group(2)) > idle_max:
r.execute_command("client", "kill", match.group(1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment