From e4bf1b243e0282bcba650d006982804ee560eff5 Mon Sep 17 00:00:00 2001 From: Kam Karshenas Date: Wed, 2 Nov 2016 16:12:20 -0400 Subject: [PATCH 1/3] flush specific redis namespaces via rake --- lib/tasks/redis.rake | 21 +++++++++++++++++++++ 1 file changed, 21 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..b28737ddb4a --- /dev/null +++ b/lib/tasks/redis.rake @@ -0,0 +1,21 @@ +# 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 do + namespace = Session.new.redis_namespace.namespace + Redis.current.scan_each(match: /^#{namespace}/) do |key| + redis.del(key) + end + end + + desc 'Flush RedisStore: User' + task :flush_users_store do + namespace = User.new.redis_namespace.namespace + Redis.current.scan_each(match: /^#{namespace}/) do |key| + redis.del(key) + end + end +end From a8b02763e17a1e9981af7935c5e7a41c116d6551 Mon Sep 17 00:00:00 2001 From: Kam Karshenas Date: Wed, 2 Nov 2016 16:14:08 -0400 Subject: [PATCH 2/3] minor fix --- lib/tasks/redis.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tasks/redis.rake b/lib/tasks/redis.rake index b28737ddb4a..502bee1c9b4 100644 --- a/lib/tasks/redis.rake +++ b/lib/tasks/redis.rake @@ -6,7 +6,8 @@ namespace :redis do desc 'Flush RedisStore: Session' task :flush_session_store do namespace = Session.new.redis_namespace.namespace - Redis.current.scan_each(match: /^#{namespace}/) do |key| + redis = Redis.current + redis.scan_each(match: /^#{namespace}/) do |key| redis.del(key) end end @@ -14,7 +15,8 @@ namespace :redis do desc 'Flush RedisStore: User' task :flush_users_store do namespace = User.new.redis_namespace.namespace - Redis.current.scan_each(match: /^#{namespace}/) do |key| + redis = Redis.current + redis.scan_each(match: /^#{namespace}/) do |key| redis.del(key) end end From 9153b90730523037616809a02b68af60c8e8ff78 Mon Sep 17 00:00:00 2001 From: Kam Karshenas Date: Wed, 2 Nov 2016 19:28:01 -0400 Subject: [PATCH 3/3] allow rake task to invoke environment for models --- lib/tasks/redis.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/redis.rake b/lib/tasks/redis.rake index 502bee1c9b4..fd9871dba3d 100644 --- a/lib/tasks/redis.rake +++ b/lib/tasks/redis.rake @@ -4,19 +4,19 @@ namespace :redis do task flush_session: [:flush_session_store, :flush_users_store] desc 'Flush RedisStore: Session' - task :flush_session_store do + task flush_session_store: :environment do namespace = Session.new.redis_namespace.namespace redis = Redis.current - redis.scan_each(match: /^#{namespace}/) do |key| + redis.scan_each(match: "#{namespace}:*") do |key| redis.del(key) end end desc 'Flush RedisStore: User' - task :flush_users_store do + task flush_users_store: :environment do namespace = User.new.redis_namespace.namespace redis = Redis.current - redis.scan_each(match: /^#{namespace}/) do |key| + redis.scan_each(match: "#{namespace}:*") do |key| redis.del(key) end end