Last active
August 29, 2015 14:11
-
-
Save gaurish/eae003152b661fce6863 to your computer and use it in GitHub Desktop.
delete keys in redis using scan method
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
require 'redis' | |
require 'yaml' | |
require 'redis/connection/hiredis' | |
require 'redis-namespace' | |
def redis_config | |
YAML.load_file('/home/prodeng/apps/shared/config/redis.yml')['production'] | |
end | |
def redis | |
r = Redis.new(:host => redis_config["host"], | |
:port => redis_config["port"], | |
:driver => redis_config["driver"].to_sym, | |
:password => redis_config["password"]) | |
Redis::Namespace.new('production', redis: r) | |
end | |
def conn | |
@redis ||= redis | |
end | |
conn.scan_each(match: 'B[_|Z]*') do |key| | |
conn.del(key) | |
end | |
conn.scan_each(match: 'LK:*') do |key| | |
conn.del(key) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment