Skip to content

Instantly share code, notes, and snippets.

View weeyum's full-sized avatar

William Li weeyum

  • Airbnb
  • California
View GitHub Profile
@weeyum
weeyum / kill_idle_redis_connections.rb
Last active June 9, 2016 20:10
kill redis connections
for_real = false
idle_max = 86400
# redis_constant is a connection pool, the variable c is a single redis client
(clients = redis_constant.with { |c| c.method_missing("client", "list") }.split("\n")).nil?
(addrs = clients.
# select idle clients
select { |client_string| client_string.match(/idle=([\d|\.|:]*)/).captures.first.to_i > idle_max }.
# return ip addresses
map { |client_string| client_string.match(/addr=([\d|\.|:]*)/).captures.first }).nil?