Skip to content

Instantly share code, notes, and snippets.

@gaurish
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurish/eae003152b661fce6863 to your computer and use it in GitHub Desktop.
Save gaurish/eae003152b661fce6863 to your computer and use it in GitHub Desktop.
delete keys in redis using scan method
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