redis_set_store 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +29 -0
- data/.rspec +2 -0
- data/.rubocop.yml +25 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Appraisals +13 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.md +157 -0
- data/Rakefile +17 -0
- data/bin/console +8 -0
- data/bin/setup +6 -0
- data/gemfiles/rails_4_2.gemfile +7 -0
- data/gemfiles/rails_4_2.gemfile.lock +178 -0
- data/gemfiles/rails_5_0.gemfile +7 -0
- data/gemfiles/rails_5_0.gemfile.lock +185 -0
- data/gemfiles/rails_5_1.gemfile +7 -0
- data/gemfiles/rails_5_1.gemfile.lock +185 -0
- data/lib/active_support/cache/redis_set_store.rb +169 -0
- data/lib/redis_set_store.rb +20 -0
- data/lib/redis_set_store/bootstrap.rb +76 -0
- data/lib/redis_set_store/railtie.rb +13 -0
- data/lib/redis_set_store/version.rb +5 -0
- data/redis_set_store.gemspec +39 -0
- metadata +240 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
redis_set_store (0.1.0)
|
5
|
+
activesupport (>= 4.2)
|
6
|
+
railties (>= 4.2)
|
7
|
+
redis (~> 3.0)
|
8
|
+
redis-rails (~> 5.0)
|
9
|
+
redis-store (~> 1.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
actioncable (5.0.5)
|
15
|
+
actionpack (= 5.0.5)
|
16
|
+
nio4r (>= 1.2, < 3.0)
|
17
|
+
websocket-driver (~> 0.6.1)
|
18
|
+
actionmailer (5.0.5)
|
19
|
+
actionpack (= 5.0.5)
|
20
|
+
actionview (= 5.0.5)
|
21
|
+
activejob (= 5.0.5)
|
22
|
+
mail (~> 2.5, >= 2.5.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
actionpack (5.0.5)
|
25
|
+
actionview (= 5.0.5)
|
26
|
+
activesupport (= 5.0.5)
|
27
|
+
rack (~> 2.0)
|
28
|
+
rack-test (~> 0.6.3)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
31
|
+
actionview (5.0.5)
|
32
|
+
activesupport (= 5.0.5)
|
33
|
+
builder (~> 3.1)
|
34
|
+
erubis (~> 2.7.0)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
37
|
+
activejob (5.0.5)
|
38
|
+
activesupport (= 5.0.5)
|
39
|
+
globalid (>= 0.3.6)
|
40
|
+
activemodel (5.0.5)
|
41
|
+
activesupport (= 5.0.5)
|
42
|
+
activerecord (5.0.5)
|
43
|
+
activemodel (= 5.0.5)
|
44
|
+
activesupport (= 5.0.5)
|
45
|
+
arel (~> 7.0)
|
46
|
+
activesupport (5.0.5)
|
47
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
+
i18n (~> 0.7)
|
49
|
+
minitest (~> 5.1)
|
50
|
+
tzinfo (~> 1.1)
|
51
|
+
appraisal (2.2.0)
|
52
|
+
bundler
|
53
|
+
rake
|
54
|
+
thor (>= 0.14.0)
|
55
|
+
arel (7.1.4)
|
56
|
+
ast (2.3.0)
|
57
|
+
builder (3.2.3)
|
58
|
+
bundler-audit (0.6.0)
|
59
|
+
bundler (~> 1.2)
|
60
|
+
thor (~> 0.18)
|
61
|
+
concurrent-ruby (1.0.5)
|
62
|
+
diff-lcs (1.3)
|
63
|
+
erubis (2.7.0)
|
64
|
+
globalid (0.4.0)
|
65
|
+
activesupport (>= 4.2.0)
|
66
|
+
i18n (0.8.6)
|
67
|
+
loofah (2.0.3)
|
68
|
+
nokogiri (>= 1.5.9)
|
69
|
+
mail (2.6.6)
|
70
|
+
mime-types (>= 1.16, < 4)
|
71
|
+
metaclass (0.0.4)
|
72
|
+
method_source (0.8.2)
|
73
|
+
mime-types (3.1)
|
74
|
+
mime-types-data (~> 3.2015)
|
75
|
+
mime-types-data (3.2016.0521)
|
76
|
+
mini_portile2 (2.2.0)
|
77
|
+
minitest (5.10.3)
|
78
|
+
mocha (1.2.1)
|
79
|
+
metaclass (~> 0.0.1)
|
80
|
+
nio4r (2.1.0)
|
81
|
+
nokogiri (1.8.0)
|
82
|
+
mini_portile2 (~> 2.2.0)
|
83
|
+
parallel (1.12.0)
|
84
|
+
parser (2.4.0.0)
|
85
|
+
ast (~> 2.2)
|
86
|
+
powerpack (0.1.1)
|
87
|
+
rack (2.0.3)
|
88
|
+
rack-test (0.6.3)
|
89
|
+
rack (>= 1.0)
|
90
|
+
rails (5.0.5)
|
91
|
+
actioncable (= 5.0.5)
|
92
|
+
actionmailer (= 5.0.5)
|
93
|
+
actionpack (= 5.0.5)
|
94
|
+
actionview (= 5.0.5)
|
95
|
+
activejob (= 5.0.5)
|
96
|
+
activemodel (= 5.0.5)
|
97
|
+
activerecord (= 5.0.5)
|
98
|
+
activesupport (= 5.0.5)
|
99
|
+
bundler (>= 1.3.0)
|
100
|
+
railties (= 5.0.5)
|
101
|
+
sprockets-rails (>= 2.0.0)
|
102
|
+
rails-dom-testing (2.0.3)
|
103
|
+
activesupport (>= 4.2.0)
|
104
|
+
nokogiri (>= 1.6)
|
105
|
+
rails-html-sanitizer (1.0.3)
|
106
|
+
loofah (~> 2.0)
|
107
|
+
railties (5.0.5)
|
108
|
+
actionpack (= 5.0.5)
|
109
|
+
activesupport (= 5.0.5)
|
110
|
+
method_source
|
111
|
+
rake (>= 0.8.7)
|
112
|
+
thor (>= 0.18.1, < 2.0)
|
113
|
+
rainbow (2.2.2)
|
114
|
+
rake
|
115
|
+
rake (10.5.0)
|
116
|
+
redis (3.3.3)
|
117
|
+
redis-actionpack (5.0.1)
|
118
|
+
actionpack (>= 4.0, < 6)
|
119
|
+
redis-rack (>= 1, < 3)
|
120
|
+
redis-store (>= 1.1.0, < 1.4.0)
|
121
|
+
redis-activesupport (5.0.3)
|
122
|
+
activesupport (>= 3, < 6)
|
123
|
+
redis-store (~> 1.3.0)
|
124
|
+
redis-rack (2.0.2)
|
125
|
+
rack (>= 1.5, < 3)
|
126
|
+
redis-store (>= 1.2, < 1.4)
|
127
|
+
redis-rails (5.0.2)
|
128
|
+
redis-actionpack (>= 5.0, < 6)
|
129
|
+
redis-activesupport (>= 5.0, < 6)
|
130
|
+
redis-store (>= 1.2, < 2)
|
131
|
+
redis-store (1.3.0)
|
132
|
+
redis (>= 2.2)
|
133
|
+
rspec (3.5.0)
|
134
|
+
rspec-core (~> 3.5.0)
|
135
|
+
rspec-expectations (~> 3.5.0)
|
136
|
+
rspec-mocks (~> 3.5.0)
|
137
|
+
rspec-core (3.5.4)
|
138
|
+
rspec-support (~> 3.5.0)
|
139
|
+
rspec-expectations (3.5.0)
|
140
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
141
|
+
rspec-support (~> 3.5.0)
|
142
|
+
rspec-mocks (3.5.0)
|
143
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
144
|
+
rspec-support (~> 3.5.0)
|
145
|
+
rspec-support (3.5.0)
|
146
|
+
rubocop (0.49.1)
|
147
|
+
parallel (~> 1.10)
|
148
|
+
parser (>= 2.3.3.1, < 3.0)
|
149
|
+
powerpack (~> 0.1)
|
150
|
+
rainbow (>= 1.99.1, < 3.0)
|
151
|
+
ruby-progressbar (~> 1.7)
|
152
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
153
|
+
ruby-progressbar (1.8.1)
|
154
|
+
sprockets (3.7.1)
|
155
|
+
concurrent-ruby (~> 1.0)
|
156
|
+
rack (> 1, < 3)
|
157
|
+
sprockets-rails (3.2.0)
|
158
|
+
actionpack (>= 4.0)
|
159
|
+
activesupport (>= 4.0)
|
160
|
+
sprockets (>= 3.0.0)
|
161
|
+
thor (0.19.4)
|
162
|
+
thread_safe (0.3.6)
|
163
|
+
tzinfo (1.2.3)
|
164
|
+
thread_safe (~> 0.1)
|
165
|
+
unicode-display_width (1.3.0)
|
166
|
+
websocket-driver (0.6.5)
|
167
|
+
websocket-extensions (>= 0.1.0)
|
168
|
+
websocket-extensions (0.1.2)
|
169
|
+
|
170
|
+
PLATFORMS
|
171
|
+
ruby
|
172
|
+
|
173
|
+
DEPENDENCIES
|
174
|
+
appraisal (~> 2.0)
|
175
|
+
bundler (~> 1.15)
|
176
|
+
bundler-audit (~> 0)
|
177
|
+
mocha (~> 1)
|
178
|
+
rails (= 5.0.5)
|
179
|
+
rake (~> 10.0)
|
180
|
+
redis_set_store!
|
181
|
+
rspec (~> 3.0)
|
182
|
+
rubocop (~> 0)
|
183
|
+
|
184
|
+
BUNDLED WITH
|
185
|
+
1.15.3
|
@@ -0,0 +1,185 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
redis_set_store (0.1.0)
|
5
|
+
activesupport (>= 4.2)
|
6
|
+
railties (>= 4.2)
|
7
|
+
redis (~> 3.0)
|
8
|
+
redis-rails (~> 5.0)
|
9
|
+
redis-store (~> 1.1)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
actioncable (5.1.3)
|
15
|
+
actionpack (= 5.1.3)
|
16
|
+
nio4r (~> 2.0)
|
17
|
+
websocket-driver (~> 0.6.1)
|
18
|
+
actionmailer (5.1.3)
|
19
|
+
actionpack (= 5.1.3)
|
20
|
+
actionview (= 5.1.3)
|
21
|
+
activejob (= 5.1.3)
|
22
|
+
mail (~> 2.5, >= 2.5.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
actionpack (5.1.3)
|
25
|
+
actionview (= 5.1.3)
|
26
|
+
activesupport (= 5.1.3)
|
27
|
+
rack (~> 2.0)
|
28
|
+
rack-test (~> 0.6.3)
|
29
|
+
rails-dom-testing (~> 2.0)
|
30
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
31
|
+
actionview (5.1.3)
|
32
|
+
activesupport (= 5.1.3)
|
33
|
+
builder (~> 3.1)
|
34
|
+
erubi (~> 1.4)
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
37
|
+
activejob (5.1.3)
|
38
|
+
activesupport (= 5.1.3)
|
39
|
+
globalid (>= 0.3.6)
|
40
|
+
activemodel (5.1.3)
|
41
|
+
activesupport (= 5.1.3)
|
42
|
+
activerecord (5.1.3)
|
43
|
+
activemodel (= 5.1.3)
|
44
|
+
activesupport (= 5.1.3)
|
45
|
+
arel (~> 8.0)
|
46
|
+
activesupport (5.1.3)
|
47
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
+
i18n (~> 0.7)
|
49
|
+
minitest (~> 5.1)
|
50
|
+
tzinfo (~> 1.1)
|
51
|
+
appraisal (2.2.0)
|
52
|
+
bundler
|
53
|
+
rake
|
54
|
+
thor (>= 0.14.0)
|
55
|
+
arel (8.0.0)
|
56
|
+
ast (2.3.0)
|
57
|
+
builder (3.2.3)
|
58
|
+
bundler-audit (0.6.0)
|
59
|
+
bundler (~> 1.2)
|
60
|
+
thor (~> 0.18)
|
61
|
+
concurrent-ruby (1.0.5)
|
62
|
+
diff-lcs (1.3)
|
63
|
+
erubi (1.6.1)
|
64
|
+
globalid (0.4.0)
|
65
|
+
activesupport (>= 4.2.0)
|
66
|
+
i18n (0.8.6)
|
67
|
+
loofah (2.0.3)
|
68
|
+
nokogiri (>= 1.5.9)
|
69
|
+
mail (2.6.6)
|
70
|
+
mime-types (>= 1.16, < 4)
|
71
|
+
metaclass (0.0.4)
|
72
|
+
method_source (0.8.2)
|
73
|
+
mime-types (3.1)
|
74
|
+
mime-types-data (~> 3.2015)
|
75
|
+
mime-types-data (3.2016.0521)
|
76
|
+
mini_portile2 (2.2.0)
|
77
|
+
minitest (5.10.3)
|
78
|
+
mocha (1.2.1)
|
79
|
+
metaclass (~> 0.0.1)
|
80
|
+
nio4r (2.1.0)
|
81
|
+
nokogiri (1.8.0)
|
82
|
+
mini_portile2 (~> 2.2.0)
|
83
|
+
parallel (1.12.0)
|
84
|
+
parser (2.4.0.0)
|
85
|
+
ast (~> 2.2)
|
86
|
+
powerpack (0.1.1)
|
87
|
+
rack (2.0.3)
|
88
|
+
rack-test (0.6.3)
|
89
|
+
rack (>= 1.0)
|
90
|
+
rails (5.1.3)
|
91
|
+
actioncable (= 5.1.3)
|
92
|
+
actionmailer (= 5.1.3)
|
93
|
+
actionpack (= 5.1.3)
|
94
|
+
actionview (= 5.1.3)
|
95
|
+
activejob (= 5.1.3)
|
96
|
+
activemodel (= 5.1.3)
|
97
|
+
activerecord (= 5.1.3)
|
98
|
+
activesupport (= 5.1.3)
|
99
|
+
bundler (>= 1.3.0)
|
100
|
+
railties (= 5.1.3)
|
101
|
+
sprockets-rails (>= 2.0.0)
|
102
|
+
rails-dom-testing (2.0.3)
|
103
|
+
activesupport (>= 4.2.0)
|
104
|
+
nokogiri (>= 1.6)
|
105
|
+
rails-html-sanitizer (1.0.3)
|
106
|
+
loofah (~> 2.0)
|
107
|
+
railties (5.1.3)
|
108
|
+
actionpack (= 5.1.3)
|
109
|
+
activesupport (= 5.1.3)
|
110
|
+
method_source
|
111
|
+
rake (>= 0.8.7)
|
112
|
+
thor (>= 0.18.1, < 2.0)
|
113
|
+
rainbow (2.2.2)
|
114
|
+
rake
|
115
|
+
rake (10.5.0)
|
116
|
+
redis (3.3.3)
|
117
|
+
redis-actionpack (5.0.1)
|
118
|
+
actionpack (>= 4.0, < 6)
|
119
|
+
redis-rack (>= 1, < 3)
|
120
|
+
redis-store (>= 1.1.0, < 1.4.0)
|
121
|
+
redis-activesupport (5.0.3)
|
122
|
+
activesupport (>= 3, < 6)
|
123
|
+
redis-store (~> 1.3.0)
|
124
|
+
redis-rack (2.0.2)
|
125
|
+
rack (>= 1.5, < 3)
|
126
|
+
redis-store (>= 1.2, < 1.4)
|
127
|
+
redis-rails (5.0.2)
|
128
|
+
redis-actionpack (>= 5.0, < 6)
|
129
|
+
redis-activesupport (>= 5.0, < 6)
|
130
|
+
redis-store (>= 1.2, < 2)
|
131
|
+
redis-store (1.3.0)
|
132
|
+
redis (>= 2.2)
|
133
|
+
rspec (3.6.0)
|
134
|
+
rspec-core (~> 3.6.0)
|
135
|
+
rspec-expectations (~> 3.6.0)
|
136
|
+
rspec-mocks (~> 3.6.0)
|
137
|
+
rspec-core (3.6.0)
|
138
|
+
rspec-support (~> 3.6.0)
|
139
|
+
rspec-expectations (3.6.0)
|
140
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
141
|
+
rspec-support (~> 3.6.0)
|
142
|
+
rspec-mocks (3.6.0)
|
143
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
144
|
+
rspec-support (~> 3.6.0)
|
145
|
+
rspec-support (3.6.0)
|
146
|
+
rubocop (0.49.1)
|
147
|
+
parallel (~> 1.10)
|
148
|
+
parser (>= 2.3.3.1, < 3.0)
|
149
|
+
powerpack (~> 0.1)
|
150
|
+
rainbow (>= 1.99.1, < 3.0)
|
151
|
+
ruby-progressbar (~> 1.7)
|
152
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
153
|
+
ruby-progressbar (1.8.1)
|
154
|
+
sprockets (3.7.1)
|
155
|
+
concurrent-ruby (~> 1.0)
|
156
|
+
rack (> 1, < 3)
|
157
|
+
sprockets-rails (3.2.0)
|
158
|
+
actionpack (>= 4.0)
|
159
|
+
activesupport (>= 4.0)
|
160
|
+
sprockets (>= 3.0.0)
|
161
|
+
thor (0.19.4)
|
162
|
+
thread_safe (0.3.6)
|
163
|
+
tzinfo (1.2.3)
|
164
|
+
thread_safe (~> 0.1)
|
165
|
+
unicode-display_width (1.3.0)
|
166
|
+
websocket-driver (0.6.5)
|
167
|
+
websocket-extensions (>= 0.1.0)
|
168
|
+
websocket-extensions (0.1.2)
|
169
|
+
|
170
|
+
PLATFORMS
|
171
|
+
ruby
|
172
|
+
|
173
|
+
DEPENDENCIES
|
174
|
+
appraisal (~> 2.0)
|
175
|
+
bundler (~> 1.15)
|
176
|
+
bundler-audit (~> 0)
|
177
|
+
mocha (~> 1)
|
178
|
+
rails (= 5.1.3)
|
179
|
+
rake (~> 10.0)
|
180
|
+
redis_set_store!
|
181
|
+
rspec (~> 3.0)
|
182
|
+
rubocop (~> 0)
|
183
|
+
|
184
|
+
BUNDLED WITH
|
185
|
+
1.15.3
|
@@ -0,0 +1,169 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Cache
|
5
|
+
# A Rails cache implementation that is backed by redis and uses sets to
|
6
|
+
# track keys for rapid expiration of large numbers of keys.
|
7
|
+
#
|
8
|
+
# Generally you would set this up in your Rails environment files:
|
9
|
+
#
|
10
|
+
# # production.rb
|
11
|
+
# Rails.application.configure do
|
12
|
+
# config.cache_store = :redis_set_store, /\Auser:\d+/
|
13
|
+
# end
|
14
|
+
class RedisSetStore < RedisStore
|
15
|
+
# Instantiate the store.
|
16
|
+
#
|
17
|
+
# set_owner_regexp: A regular expression that identifies keys within a given
|
18
|
+
# Set Owner's Redis set.
|
19
|
+
#
|
20
|
+
# For example, assume a Site model owns cache sets.
|
21
|
+
# These are defined with the cache key prefix
|
22
|
+
# "site:#{site.id}". So the appropriate argument would
|
23
|
+
# be: `/\Asite:\d+/`
|
24
|
+
#
|
25
|
+
# If not provided (or `nil` is provided), the default
|
26
|
+
# pattern is `/\A[^:]+:\d+/`. That is, it matches
|
27
|
+
# any pattern like "type:1", assuming
|
28
|
+
#
|
29
|
+
# redis_options: Standard redis_options for a ActiveSupport::Cache::RedisStore
|
30
|
+
#
|
31
|
+
# Example:
|
32
|
+
# RedisSetStore.new
|
33
|
+
# # => pattern: /\A[^:]+:\d+/, host: localhost, port: 6379, db: 0
|
34
|
+
#
|
35
|
+
# RedisSetStore.new(/\Asite:\d+/)
|
36
|
+
# # => pattern: /\Asite:\d+/, host: localhost, port: 6379, db: 0
|
37
|
+
#
|
38
|
+
# RedisSetStore.new(/\Asite:\d+/, "example.com")
|
39
|
+
# # => pattern: /\Asite:\d+/, host: example.com, port: 6379, db: 0
|
40
|
+
#
|
41
|
+
# RedisSetStore.new(/\Asite:\d+/, "example.com:23682")
|
42
|
+
# # => pattern: /\Asite:\d+/, host: example.com, port: 23682, db: 0
|
43
|
+
#
|
44
|
+
# RedisSetStore.new(/\Asite:\d+/, "example.com:23682/1")
|
45
|
+
# # => pattern: /\Asite:\d+/, host: example.com, port: 23682, db: 1
|
46
|
+
#
|
47
|
+
# See more examples at ActiveSupport::Cache::RedisStore
|
48
|
+
def initialize(set_owner_regexp = nil, redis_options = {})
|
49
|
+
if set_owner_regexp.is_a?(Regexp)
|
50
|
+
@set_owner_regexp = set_owner_regexp
|
51
|
+
else
|
52
|
+
redis_options = set_owner_regexp
|
53
|
+
set_owner_regexp = nil
|
54
|
+
end
|
55
|
+
@set_owner_regexp = set_owner_regexp || /\A[^:]+:\d+/
|
56
|
+
|
57
|
+
super(redis_options)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Delete objects for matched keys.
|
61
|
+
#
|
62
|
+
# Example:
|
63
|
+
# cache.delete_matched("user:1:rab*")
|
64
|
+
#
|
65
|
+
# Returns number of keys that were deleted or `nil` if a connection error occurs.
|
66
|
+
def delete_matched(matcher, _options = nil)
|
67
|
+
SetOwner.new(@set_owner_regexp, matcher, @data).delete_matched
|
68
|
+
rescue Errno::ECONNREFUSED
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
|
72
|
+
# Find matched keys.
|
73
|
+
#
|
74
|
+
# Example:
|
75
|
+
# cache.matched("user:1:rab*")
|
76
|
+
#
|
77
|
+
# Returns an array of matching keys or `nil` if a connection error occurs.
|
78
|
+
def matched(key)
|
79
|
+
SetOwner.new(@set_owner_regexp, key, @data).matched
|
80
|
+
rescue Errno::ECONNREFUSED
|
81
|
+
[]
|
82
|
+
end
|
83
|
+
|
84
|
+
# Ping the server.
|
85
|
+
#
|
86
|
+
# Returns "PONG" on success.
|
87
|
+
def ping
|
88
|
+
SetOwner::STORE&.ping if defined?(SetOwner::STORE)
|
89
|
+
redis.ping
|
90
|
+
end
|
91
|
+
|
92
|
+
# Instance of redis where the cache data is stored.
|
93
|
+
#
|
94
|
+
# Returns a Redis instance.
|
95
|
+
def redis
|
96
|
+
@data
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
|
101
|
+
def write_entry(key, entry, options)
|
102
|
+
if key.include?("*")
|
103
|
+
raise ArgumentError.new("Unsupported Redis key character for ActiveSupport::Cache::RedisSetStore: *")
|
104
|
+
end
|
105
|
+
|
106
|
+
SetOwner.new(@set_owner_regexp, key, @data).sadd
|
107
|
+
|
108
|
+
super
|
109
|
+
rescue Errno::ECONNREFUSED
|
110
|
+
false
|
111
|
+
end
|
112
|
+
|
113
|
+
def delete_entry(key, options)
|
114
|
+
SetOwner.new(@set_owner_regexp, key, @data).srem
|
115
|
+
|
116
|
+
super
|
117
|
+
rescue Errno::ECONNREFUSED
|
118
|
+
false
|
119
|
+
end
|
120
|
+
|
121
|
+
# Redis set wrapper for a given partition.
|
122
|
+
class SetOwner
|
123
|
+
def initialize(set_owner_regexp, key, redis)
|
124
|
+
@key = key
|
125
|
+
@set = nil
|
126
|
+
match = set_owner_regexp.match(key)
|
127
|
+
@set = match[0] if match
|
128
|
+
@redis = redis
|
129
|
+
@redis_set_store = STORE if defined?(STORE)
|
130
|
+
@redis_set_store ||= @redis
|
131
|
+
end
|
132
|
+
|
133
|
+
def sadd
|
134
|
+
return unless @set && @key
|
135
|
+
@redis_set_store.sadd(@set, @key)
|
136
|
+
end
|
137
|
+
|
138
|
+
def srem
|
139
|
+
return unless @set && @key
|
140
|
+
@redis_set_store.srem(@set, @key)
|
141
|
+
end
|
142
|
+
|
143
|
+
def delete_matched
|
144
|
+
return unless @set && @key
|
145
|
+
|
146
|
+
srem_list = matched
|
147
|
+
return if srem_list.blank?
|
148
|
+
|
149
|
+
@redis_set_store.srem(@set, srem_list)
|
150
|
+
@redis.del(srem_list)
|
151
|
+
end
|
152
|
+
|
153
|
+
def matched
|
154
|
+
return unless @set && @key
|
155
|
+
matcher_regexp = Regexp.compile(convert_wildcards_to_regex)
|
156
|
+
@redis_set_store.smembers(@set).select { |smember| matcher_regexp.match(smember) }
|
157
|
+
end
|
158
|
+
|
159
|
+
# Redis wildcard character "*" is converted to the Regexp ".*".
|
160
|
+
# All other special characters are normally-escaped.
|
161
|
+
def convert_wildcards_to_regex
|
162
|
+
key = Regexp.escape(@key.to_s)
|
163
|
+
key = key.to_s.gsub("\\*", ".*")
|
164
|
+
key << "$"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|