From e4975d568405e8a47266b0ff5c366b2ebf45b3c3 Mon Sep 17 00:00:00 2001 From: Kam Karshenas Date: Thu, 3 Nov 2016 08:13:45 -0400 Subject: [PATCH] flush specific redis namespaces via rake (#421) * flush specific redis namespaces via rake * minor fix * allow rake task to invoke environment for models --- lib/tasks/redis.rake | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 lib/tasks/redis.rake diff --git a/lib/tasks/redis.rake b/lib/tasks/redis.rake new file mode 100644 index 00000000000..fd9871dba3d --- /dev/null +++ b/lib/tasks/redis.rake @@ -0,0 +1,23 @@ +# frozen_string_literal: true +namespace :redis do + desc 'Flush Vets.gov User/Sessions' + task flush_session: [:flush_session_store, :flush_users_store] + + desc 'Flush RedisStore: Session' + task flush_session_store: :environment do + namespace = Session.new.redis_namespace.namespace + redis = Redis.current + redis.scan_each(match: "#{namespace}:*") do |key| + redis.del(key) + end + end + + desc 'Flush RedisStore: User' + task flush_users_store: :environment do + namespace = User.new.redis_namespace.namespace + redis = Redis.current + redis.scan_each(match: "#{namespace}:*") do |key| + redis.del(key) + end + end +end