-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a seperate cache-store proxy for the redis gem
While a cache-store proxy exists for the redis-store gem, no such proxy existed for using the redis gem itself. This fills that gap by adding such a proxy. Resolves #190
- Loading branch information
Showing
4 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'delegate' | ||
|
||
module Rack | ||
class Attack | ||
module StoreProxy | ||
class RedisProxy < SimpleDelegator | ||
def self.handle?(store) | ||
defined?(::Redis) && store.is_a?(::Redis) | ||
end | ||
|
||
def initialize(store) | ||
super(store) | ||
end | ||
|
||
def read(key) | ||
get(key) | ||
end | ||
|
||
def write(key, value, options={}) | ||
if (expires_in = options[:expires_in]) | ||
setex(key, expires_in, value) | ||
else | ||
set(key, value) | ||
end | ||
end | ||
|
||
def increment(key, amount, options={}) | ||
count = nil | ||
|
||
pipelined do | ||
count = incrby(key, amount) | ||
expire(key, options[:expires_in]) if options[:expires_in] | ||
end | ||
|
||
count.value if count | ||
end | ||
|
||
def delete(key, options={}) | ||
del(key) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters