redis-store 1.5.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +6 -0
- data/.github/auto-assign-issues.yml +2 -0
- data/.rubocop.yml +138 -0
- data/.travis.yml +25 -21
- data/Appraisals +6 -2
- data/CHANGELOG.md +74 -1
- data/CODEOWNERS +1 -0
- data/README.md +4 -4
- data/Rakefile +2 -0
- data/gemfiles/{redis_3_x.gemfile → redis_4_0_x.gemfile} +1 -1
- data/gemfiles/redis_4_1_x.gemfile +7 -0
- data/lib/redis/distributed_store.rb +5 -5
- data/lib/redis/store.rb +1 -2
- data/lib/redis/store/factory.rb +15 -15
- data/lib/redis/store/interface.rb +9 -1
- data/lib/redis/store/namespace.rb +115 -16
- data/lib/redis/store/redis_version.rb +0 -1
- data/lib/redis/store/ttl.rb +1 -1
- data/lib/redis/store/version.rb +1 -1
- data/redis-store.gemspec +8 -8
- data/test/redis/distributed_store_test.rb +8 -8
- data/test/redis/store/factory_test.rb +49 -17
- data/test/redis/store/interface_test.rb +4 -4
- data/test/redis/store/namespace_test.rb +145 -27
- data/test/redis/store/redis_version_test.rb +1 -2
- data/test/redis/store/serialization_test.rb +4 -4
- data/test/redis/store/ttl_test.rb +20 -2
- data/test/test_helper.rb +1 -1
- metadata +33 -15
@@ -90,52 +90,63 @@ describe "Redis::Store::Namespace" do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
describe 'method calls' do
|
93
|
-
let(:store){Redis::Store.new :namespace => @namespace, :serializer => nil}
|
94
|
-
let(:client){store.instance_variable_get(:@client)}
|
93
|
+
let(:store) { Redis::Store.new :namespace => @namespace, :serializer => nil }
|
94
|
+
let(:client) { store.instance_variable_get(:@client) }
|
95
95
|
|
96
96
|
it "should namespace get" do
|
97
|
-
|
98
|
-
|
97
|
+
client.expects(:call).with([:get, "#{@namespace}:rabbit"]).once
|
98
|
+
store.get("rabbit")
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should namespace set" do
|
102
|
-
|
103
|
-
|
102
|
+
client.expects(:call).with([:set, "#{@namespace}:rabbit", @rabbit])
|
103
|
+
store.set "rabbit", @rabbit
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should namespace setnx" do
|
107
|
-
|
108
|
-
|
107
|
+
client.expects(:call).with([:setnx, "#{@namespace}:rabbit", @rabbit])
|
108
|
+
store.setnx "rabbit", @rabbit
|
109
109
|
end
|
110
110
|
|
111
111
|
it "should namespace del with single key" do
|
112
|
-
|
113
|
-
|
112
|
+
client.expects(:call).with([:del, "#{@namespace}:rabbit"])
|
113
|
+
store.del "rabbit"
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should namespace del with multiple keys" do
|
117
|
-
|
118
|
-
|
117
|
+
client.expects(:call).with([:del, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
|
118
|
+
store.del "rabbit", "white_rabbit"
|
119
119
|
end
|
120
120
|
|
121
121
|
it "should namespace keys" do
|
122
|
-
|
123
|
-
|
122
|
+
store.set "rabbit", @rabbit
|
123
|
+
store.keys("rabb*").must_equal [ "rabbit" ]
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should namespace scan when a pattern is given" do
|
127
|
+
store.set "rabbit", @rabbit
|
128
|
+
cursor = "0"
|
129
|
+
keys = []
|
130
|
+
begin
|
131
|
+
cursor, matched_keys = store.scan(cursor, match: "rabb*")
|
132
|
+
keys = keys.concat(matched_keys) unless matched_keys.empty?
|
133
|
+
end until cursor == "0"
|
134
|
+
keys.must_equal [ "rabbit" ]
|
124
135
|
end
|
125
136
|
|
126
137
|
it "should namespace exists" do
|
127
|
-
|
128
|
-
|
138
|
+
client.expects(:call).with([:exists, "#{@namespace}:rabbit"])
|
139
|
+
store.exists "rabbit"
|
129
140
|
end
|
130
141
|
|
131
142
|
it "should namespace incrby" do
|
132
|
-
|
133
|
-
|
143
|
+
client.expects(:call).with([:incrby, "#{@namespace}:counter", 1])
|
144
|
+
store.incrby "counter", 1
|
134
145
|
end
|
135
146
|
|
136
147
|
it "should namespace decrby" do
|
137
|
-
|
138
|
-
|
148
|
+
client.expects(:call).with([:decrby, "#{@namespace}:counter", 1])
|
149
|
+
store.decrby "counter", 1
|
139
150
|
end
|
140
151
|
|
141
152
|
it "should namespace mget" do
|
@@ -154,24 +165,24 @@ describe "Redis::Store::Namespace" do
|
|
154
165
|
end
|
155
166
|
|
156
167
|
it "should namespace expire" do
|
157
|
-
|
158
|
-
|
168
|
+
client.expects(:call).with([:expire, "#{@namespace}:rabbit", 60]).once
|
169
|
+
store.expire("rabbit", 60)
|
159
170
|
end
|
160
171
|
|
161
172
|
it "should namespace ttl" do
|
162
|
-
|
163
|
-
|
173
|
+
client.expects(:call).with([:ttl, "#{@namespace}:rabbit"]).once
|
174
|
+
store.ttl("rabbit")
|
164
175
|
end
|
165
176
|
|
166
177
|
it "should namespace watch" do
|
167
|
-
client.expects(:call).with([:watch,"#{@namespace}:rabbit"]).once
|
178
|
+
client.expects(:call).with([:watch, "#{@namespace}:rabbit"]).once
|
168
179
|
store.watch("rabbit")
|
169
180
|
end
|
170
181
|
|
171
182
|
it "wraps flushdb with appropriate KEYS * calls" do
|
172
183
|
client.expects(:call).with([:flushdb]).never
|
173
|
-
client.expects(:call).with([:keys,"#{@namespace}:*"]).once.returns(["rabbit"])
|
174
|
-
client.expects(:call).with([:del,"#{@namespace}:rabbit"]).once
|
184
|
+
client.expects(:call).with([:keys, "#{@namespace}:*"]).once.returns(["rabbit"])
|
185
|
+
client.expects(:call).with([:del, "#{@namespace}:rabbit"]).once
|
175
186
|
store.flushdb
|
176
187
|
end
|
177
188
|
|
@@ -182,5 +193,112 @@ describe "Redis::Store::Namespace" do
|
|
182
193
|
store.flushdb
|
183
194
|
end
|
184
195
|
end
|
196
|
+
|
197
|
+
it "should namespace hdel" do
|
198
|
+
client.expects(:call).with([:hdel, "#{@namespace}:rabbit", "key1", "key2"]).once
|
199
|
+
store.hdel("rabbit", "key1", "key2")
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should namespace hget" do
|
203
|
+
client.expects(:call).with([:hget, "#{@namespace}:rabbit", "key"]).once
|
204
|
+
store.hget("rabbit", "key")
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should namespace hgetall" do
|
208
|
+
client.expects(:call).with([:hgetall, "#{@namespace}:rabbit"]).once
|
209
|
+
store.hgetall("rabbit")
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should namespace hexists" do
|
213
|
+
client.expects(:call).with([:hexists, "#{@namespace}:rabbit", "key"]).once
|
214
|
+
results = store.hexists("rabbit", "key")
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should namespace hincrby" do
|
218
|
+
client.expects(:call).with([:hincrby, "#{@namespace}:rabbit", "key", 1]).once
|
219
|
+
store.hincrby("rabbit", "key", 1)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should namespace hincrbyfloat" do
|
223
|
+
client.expects(:call).with([:hincrby, "#{@namespace}:rabbit", "key", 1.5]).once
|
224
|
+
store.hincrby("rabbit", "key", 1.5)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should namespace hkeys" do
|
228
|
+
client.expects(:call).with([:hkeys, "#{@namespace}:rabbit"])
|
229
|
+
store.hkeys("rabbit")
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should namespace hlen" do
|
233
|
+
client.expects(:call).with([:hlen, "#{@namespace}:rabbit"])
|
234
|
+
store.hlen("rabbit")
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should namespace hmget" do
|
238
|
+
client.expects(:call).with([:hmget, "#{@namespace}:rabbit", "key1", "key2"])
|
239
|
+
store.hmget("rabbit", "key1", "key2")
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should namespace hmset" do
|
243
|
+
client.expects(:call).with([:hmset, "#{@namespace}:rabbit", "key", @rabbit])
|
244
|
+
store.hmset("rabbit", "key", @rabbit)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should namespace hset" do
|
248
|
+
client.expects(:call).with([:hset, "#{@namespace}:rabbit", "key", @rabbit])
|
249
|
+
store.hset("rabbit", "key", @rabbit)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should namespace hsetnx" do
|
253
|
+
client.expects(:call).with([:hsetnx, "#{@namespace}:rabbit", "key", @rabbit])
|
254
|
+
store.hsetnx("rabbit", "key", @rabbit)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should namespace hvals" do
|
258
|
+
client.expects(:call).with([:hvals, "#{@namespace}:rabbit"])
|
259
|
+
store.hvals("rabbit")
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should namespace hscan" do
|
263
|
+
client.expects(:call).with([:hscan, "#{@namespace}:rabbit", 0])
|
264
|
+
store.hscan("rabbit", 0)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should namespace hscan_each with block" do
|
268
|
+
client.call([:hset, "#{@namespace}:rabbit", "key1", @rabbit])
|
269
|
+
client.expects(:call).with([:hscan, "#{@namespace}:rabbit", 0]).returns(["0", ["key1"]])
|
270
|
+
results = []
|
271
|
+
store.hscan_each("rabbit") do |key|
|
272
|
+
results << key
|
273
|
+
end
|
274
|
+
results.must_equal(["key1"])
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should namespace hscan_each without block" do
|
278
|
+
client.call([:hset, "#{@namespace}:rabbit", "key1", @rabbit])
|
279
|
+
client.expects(:call).with([:hscan, "#{@namespace}:rabbit", 0]).returns(["0", ["key1"]])
|
280
|
+
results = store.hscan_each("rabbit").to_a
|
281
|
+
results.must_equal(["key1"])
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should namespace zincrby" do
|
285
|
+
client.expects(:call).with([:zincrby, "#{@namespace}:rabbit", 1.0, "member"])
|
286
|
+
store.zincrby("rabbit", 1.0, "member")
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should namespace zscore" do
|
290
|
+
client.expects(:call).with([:zscore, "#{@namespace}:rabbit", "member"])
|
291
|
+
store.zscore("rabbit", "member")
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should namespace zadd" do
|
295
|
+
client.expects(:call).with([:zadd, "#{@namespace}:rabbit", 1.0, "member"])
|
296
|
+
store.zadd("rabbit", 1.0, "member")
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should namespace zrem" do
|
300
|
+
client.expects(:call).with([:zrem, "#{@namespace}:rabbit", "member"])
|
301
|
+
store.zrem("rabbit", "member")
|
302
|
+
end
|
185
303
|
end
|
186
304
|
end
|
@@ -81,8 +81,8 @@ describe "Redis::Serialization" do
|
|
81
81
|
|
82
82
|
it "marshals setex (over a distributed store)" do
|
83
83
|
@store = Redis::DistributedStore.new [
|
84
|
-
{:host => "localhost", :port => "6380", :db => 0},
|
85
|
-
{:host => "localhost", :port => "6381", :db => 0}
|
84
|
+
{ :host => "localhost", :port => "6380", :db => 0 },
|
85
|
+
{ :host => "localhost", :port => "6381", :db => 0 }
|
86
86
|
]
|
87
87
|
@store.setex "rabbit", 50, @white_rabbit
|
88
88
|
@store.get("rabbit").must_equal(@white_rabbit)
|
@@ -90,8 +90,8 @@ describe "Redis::Serialization" do
|
|
90
90
|
|
91
91
|
it "doesn't marshal setex if raw option is true (over a distributed store)" do
|
92
92
|
@store = Redis::DistributedStore.new [
|
93
|
-
{:host => "localhost", :port => "6380", :db => 0},
|
94
|
-
{:host => "localhost", :port => "6381", :db => 0}
|
93
|
+
{ :host => "localhost", :port => "6380", :db => 0 },
|
94
|
+
{ :host => "localhost", :port => "6381", :db => 0 }
|
95
95
|
]
|
96
96
|
@store.setex "rabbit", 50, @white_rabbit, :raw => true
|
97
97
|
@store.get("rabbit", :raw => true).must_equal(%(#<OpenStruct color="white">))
|
@@ -50,7 +50,6 @@ class MockRedis
|
|
50
50
|
def has_expire?(*a)
|
51
51
|
@expires.include?(a)
|
52
52
|
end
|
53
|
-
|
54
53
|
end
|
55
54
|
|
56
55
|
class MockTtlStore < MockRedis
|
@@ -80,7 +79,7 @@ describe MockTtlStore do
|
|
80
79
|
|
81
80
|
describe 'with nx and ex option' do
|
82
81
|
it 'must call super with key and value and options' do
|
83
|
-
set_options = {nx: true, ex: 3600}
|
82
|
+
set_options = { nx: true, ex: 3600 }
|
84
83
|
redis.set(key, mock_value, set_options)
|
85
84
|
redis.has_set?(key, mock_value, set_options).must_equal true
|
86
85
|
end
|
@@ -134,6 +133,25 @@ describe MockTtlStore do
|
|
134
133
|
redis.has_expire?(key, options[:expire_after]).must_equal true
|
135
134
|
end
|
136
135
|
end
|
136
|
+
|
137
|
+
describe 'using a redis cluster' do
|
138
|
+
let(:options) { { :expire_after => 3600, :cluster => %w[redis://127.0.0.1:6379/0] } }
|
139
|
+
|
140
|
+
it 'uses the redis pipelined feature to chain commands' do
|
141
|
+
redis.expects(:pipelined)
|
142
|
+
redis.setnx(key, mock_value, options)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'must call setnx with key and value and set raw to true' do
|
146
|
+
redis.setnx(key, mock_value, options)
|
147
|
+
redis.has_setnx?(key, mock_value, :raw => true).must_equal true
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'must call expire' do
|
151
|
+
redis.setnx(key, mock_value, options)
|
152
|
+
redis.has_expire?(key, options[:expire_after]).must_equal true
|
153
|
+
end
|
154
|
+
end
|
137
155
|
end
|
138
156
|
end
|
139
157
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '4'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5'
|
@@ -34,30 +34,30 @@ dependencies:
|
|
34
34
|
name: rake
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 12.3.3
|
40
40
|
type: :development
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- - "
|
44
|
+
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 12.3.3
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: mocha
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,6 +156,20 @@ dependencies:
|
|
156
156
|
- - "~>"
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '2.0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: rubocop
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0.54'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - "~>"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0.54'
|
159
173
|
description: Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for
|
160
174
|
Ruby web frameworks.
|
161
175
|
email:
|
@@ -164,15 +178,20 @@ executables: []
|
|
164
178
|
extensions: []
|
165
179
|
extra_rdoc_files: []
|
166
180
|
files:
|
181
|
+
- ".codeclimate.yml"
|
182
|
+
- ".github/auto-assign-issues.yml"
|
167
183
|
- ".gitignore"
|
184
|
+
- ".rubocop.yml"
|
168
185
|
- ".travis.yml"
|
169
186
|
- Appraisals
|
170
187
|
- CHANGELOG.md
|
188
|
+
- CODEOWNERS
|
171
189
|
- Gemfile
|
172
190
|
- MIT-LICENSE
|
173
191
|
- README.md
|
174
192
|
- Rakefile
|
175
|
-
- gemfiles/
|
193
|
+
- gemfiles/redis_4_0_x.gemfile
|
194
|
+
- gemfiles/redis_4_1_x.gemfile
|
176
195
|
- gemfiles/redis_4_x.gemfile
|
177
196
|
- lib/redis-store.rb
|
178
197
|
- lib/redis/distributed_store.rb
|
@@ -214,8 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
233
|
- !ruby/object:Gem::Version
|
215
234
|
version: '0'
|
216
235
|
requirements: []
|
217
|
-
|
218
|
-
rubygems_version: 2.7.3
|
236
|
+
rubygems_version: 3.1.2
|
219
237
|
signing_key:
|
220
238
|
specification_version: 4
|
221
239
|
summary: Redis stores for Ruby frameworks
|