From ff15447f3aefc9af64c152687f2280fb011c9a65 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 15 Mar 2015 11:57:12 -0700 Subject: [PATCH] Support delete method for Redis --- lib/rack/attack/store_proxy/redis_store_proxy.rb | 4 ++++ spec/integration/rack_attack_cache_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/rack/attack/store_proxy/redis_store_proxy.rb b/lib/rack/attack/store_proxy/redis_store_proxy.rb index 5677898..6718a31 100644 --- a/lib/rack/attack/store_proxy/redis_store_proxy.rb +++ b/lib/rack/attack/store_proxy/redis_store_proxy.rb @@ -36,6 +36,10 @@ module Rack rescue Redis::BaseError end + def delete(key, options={}) + self.del(key) + rescue Redis::BaseError + end end end end diff --git a/spec/integration/rack_attack_cache_spec.rb b/spec/integration/rack_attack_cache_spec.rb index 461162c..11012b9 100644 --- a/spec/integration/rack_attack_cache_spec.rb +++ b/spec/integration/rack_attack_cache_spec.rb @@ -80,6 +80,15 @@ describe Rack::Attack::Cache do @cache.read("cache-test-key").must_equal "foobar" end end + + describe "delete" do + it "must delete the value" do + store.write(@key, "foobar", :expires_in => @expires_in) + @cache.read('cache-test-key').must_equal "foobar" + store.delete(@key) + @cache.read('cache-test-key').must_equal nil + end + end end end