|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -require 'delegate' |
4 | | - |
5 | 3 | module Rack |
6 | 4 | class Attack |
7 | | - module StoreProxy |
8 | | - class ActiveSupportRedisStoreProxy < SimpleDelegator |
| 5 | + module StoreAdapters |
| 6 | + class ActiveSupportRedisStoreAdapter < StoreAdapter |
9 | 7 | def self.handle?(store) |
10 | 8 | defined?(::Redis) && |
11 | 9 | defined?(::ActiveSupport::Cache::RedisStore) && |
12 | 10 | store.is_a?(::ActiveSupport::Cache::RedisStore) |
13 | 11 | end |
14 | 12 |
|
15 | | - def increment(name, amount = 1, options = {}) |
| 13 | + def increment(key, amount = 1, options = {}) |
16 | 14 | # #increment ignores options[:expires_in]. |
17 | 15 | # |
18 | 16 | # So in order to workaround this we use #write (which sets expiration) to initialize |
19 | 17 | # the counter. After that we continue using the original #increment. |
20 | | - if options[:expires_in] && !read(name) |
21 | | - write(name, amount, options) |
| 18 | + if options[:expires_in] && !read(key) |
| 19 | + write(key, amount, options) |
22 | 20 |
|
23 | 21 | amount |
24 | 22 | else |
25 | | - super |
| 23 | + store.increment(key, amount, options) |
26 | 24 | end |
27 | 25 | end |
28 | 26 |
|
29 | | - def read(name, options = {}) |
30 | | - super(name, options.merge!(raw: true)) |
| 27 | + def read(key, options = {}) |
| 28 | + store.read(key, options.merge!(raw: true)) |
| 29 | + end |
| 30 | + |
| 31 | + def write(key, value, options = {}) |
| 32 | + store.write(key, value, options.merge!(raw: true)) |
31 | 33 | end |
32 | 34 |
|
33 | | - def write(name, value, options = {}) |
34 | | - super(name, value, options.merge!(raw: true)) |
| 35 | + def delete(key, options = {}) |
| 36 | + store.delete(key, options) |
35 | 37 | end |
36 | 38 | end |
37 | 39 | end |
|
0 commit comments