Created
March 31, 2018 05:24
-
-
Save murarisumit/8538551ea70d6744c30f73829efdca45 to your computer and use it in GitHub Desktop.
KIll redis idle connection
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
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