Skip to content

Instantly share code, notes, and snippets.

View kennethteh90's full-sized avatar

Kenneth Teh kennethteh90

View GitHub Profile
@kennethteh90
kennethteh90 / clear_redis_script.rb
Created January 20, 2020 03:03 — forked from brasic/clear_redis_script.rb
Clear a large number of redis keys by pattern using SCAN and pipelining
#!/usr/bin/env ruby
require 'redis'
# Clear a large number of keys matching a pattern using SCAN and
# pipelining to avoid killing the server.
class ClearKeys
def initialize(pattern, host='localhost', postprocess_pattern=nil)
@redis = Redis.new(host: host)
@pattern = pattern