Skip to content

Instantly share code, notes, and snippets.

View shaundr's full-sized avatar

Shaun Russell shaundr

View GitHub Profile
@shaundr
shaundr / clear_redis_script.rb
Created October 25, 2017 18:18 — 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