From e9566dbeaf3fbff6c7ff48c50b5dbd6d4a2051a7 Mon Sep 17 00:00:00 2001 From: Alfonso Juan Dillera Date: Fri, 25 Oct 2013 17:04:48 +0800 Subject: [PATCH] Added flush method. --- lib/aviator/session_pool/session_pool.rb | 5 +++++ .../aviator/session_pool/session_pool_test.rb | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/aviator/session_pool/session_pool.rb b/lib/aviator/session_pool/session_pool.rb index b262f89..477ae50 100644 --- a/lib/aviator/session_pool/session_pool.rb +++ b/lib/aviator/session_pool/session_pool.rb @@ -85,6 +85,11 @@ def set_current(key) end + def flush + redis.keys("#{ REDIS_KEY_PREFIX }*").each{ |key| redis.del(key) } + end + + private def build_key(key) diff --git a/test/aviator/session_pool/session_pool_test.rb b/test/aviator/session_pool/session_pool_test.rb index 14acc2e..6898faa 100644 --- a/test/aviator/session_pool/session_pool_test.rb +++ b/test/aviator/session_pool/session_pool_test.rb @@ -220,6 +220,25 @@ def validate end + + describe '::flush' do + + it 'deletes all keys in Redis that starts with the REDIS_KEY_PREFIX' do + keys = ['somestring', 'anotherstring', 'wellthisisanotherstring'] + + keys.each do |key| + subject[key] = session + + key = subject.send(:build_key, key) + end + + subject.flush + + keys.each{ |key| redis.get(key).must_be_nil } + end + + end + end end