redis-store 1.9.1 → 1.10.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/.github/release.yml +13 -0
- data/.github/workflows/ci.yml +64 -0
- data/.github/workflows/publish.yml +32 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +5 -11
- data/Appraisals +8 -1
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/Rakefile +3 -2
- data/gemfiles/redis_4_6_x.gemfile +7 -0
- data/gemfiles/redis_5_x.gemfile +7 -0
- data/lib/redis/distributed_store.rb +2 -0
- data/lib/redis/store/factory.rb +1 -0
- data/lib/redis/store/namespace.rb +1 -1
- data/lib/redis/store/ttl.rb +7 -2
- data/lib/redis/store/version.rb +8 -1
- data/lib/redis/store.rb +25 -8
- data/redis-store.gemspec +2 -2
- data/test/redis/distributed_store_test.rb +14 -14
- data/test/redis/store/factory_test.rb +62 -46
- data/test/redis/store/namespace_test.rb +77 -64
- data/test/redis/store/redis_version_test.rb +6 -6
- data/test/redis/store/serialization_test.rb +48 -46
- data/test/redis/store/ttl_test.rb +6 -21
- data/test/redis/store/version_test.rb +1 -1
- data/test/redis/store_test.rb +7 -7
- data/test/test_helper.rb +1 -2
- metadata +12 -8
- data/.travis.yml +0 -39
@@ -6,55 +6,60 @@ describe "Redis::Store::Factory" do
|
|
6
6
|
describe "when not given any arguments" do
|
7
7
|
it "instantiates Redis::Store" do
|
8
8
|
store = Redis::Store::Factory.create
|
9
|
-
store.must_be_kind_of(Redis::Store)
|
10
|
-
|
9
|
+
_(store).must_be_kind_of(Redis::Store)
|
10
|
+
# `redis.rb` use different default host values in v4 & v5
|
11
|
+
_(store.to_s).must_match(%r{^Redis Client connected to (127.0.0.1|localhost):6379 against DB 0$})
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "when given a Hash" do
|
15
16
|
it "uses specified host" do
|
16
17
|
store = Redis::Store::Factory.create :host => "localhost"
|
17
|
-
store.to_s.must_equal("Redis Client connected to localhost:6379 against DB 0")
|
18
|
+
_(store.to_s).must_equal("Redis Client connected to localhost:6379 against DB 0")
|
18
19
|
end
|
19
20
|
|
20
21
|
it "uses specified port" do
|
21
22
|
store = Redis::Store::Factory.create :host => "localhost", :port => 6380
|
22
|
-
store.to_s.must_equal("Redis Client connected to localhost:6380 against DB 0")
|
23
|
+
_(store.to_s).must_equal("Redis Client connected to localhost:6380 against DB 0")
|
23
24
|
end
|
24
25
|
|
25
26
|
it "uses specified scheme" do
|
26
27
|
store = Redis::Store::Factory.create :scheme => "rediss"
|
27
|
-
store.instance_variable_get(:@client)
|
28
|
+
client = store.instance_variable_get(:@client)
|
29
|
+
# `redis-client` does NOT have `scheme`
|
30
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('rediss')
|
28
31
|
end
|
29
32
|
|
30
33
|
it "uses specified path" do
|
31
34
|
store = Redis::Store::Factory.create :path => "/var/run/redis.sock"
|
32
|
-
store.to_s.must_equal("Redis Client connected to /var/run/redis.sock against DB 0")
|
35
|
+
_(store.to_s).must_equal("Redis Client connected to /var/run/redis.sock against DB 0")
|
33
36
|
end
|
34
37
|
|
35
38
|
it "uses specified db" do
|
36
39
|
store = Redis::Store::Factory.create :host => "localhost", :port => 6380, :db => 13
|
37
|
-
store.to_s.must_equal("Redis Client connected to localhost:6380 against DB 13")
|
40
|
+
_(store.to_s).must_equal("Redis Client connected to localhost:6380 against DB 13")
|
38
41
|
end
|
39
42
|
|
40
43
|
it "uses specified namespace" do
|
41
44
|
store = Redis::Store::Factory.create :namespace => "theplaylist"
|
42
|
-
|
45
|
+
# `redis.rb` use different default host values in v4 & v5
|
46
|
+
_(store.to_s).must_match(%r{^Redis Client connected to (127.0.0.1|localhost):6379 against DB 0 with namespace theplaylist$})
|
43
47
|
end
|
44
48
|
|
45
49
|
it "uses specified key_prefix as namespace" do
|
46
50
|
store = Redis::Store::Factory.create :key_prefix => "theplaylist"
|
47
|
-
|
51
|
+
# `redis.rb` use different default host values in v4 & v5
|
52
|
+
_(store.to_s).must_match(%r{^Redis Client connected to (127.0.0.1|localhost):6379 against DB 0 with namespace theplaylist$})
|
48
53
|
end
|
49
54
|
|
50
55
|
it "uses specified password" do
|
51
56
|
store = Redis::Store::Factory.create :password => "secret"
|
52
|
-
store.instance_variable_get(:@client).password.must_equal("secret")
|
57
|
+
_(store.instance_variable_get(:@client).password).must_equal("secret")
|
53
58
|
end
|
54
59
|
|
55
60
|
it 'uses empty password' do
|
56
61
|
store = Redis::Store::Factory.create :password => ''
|
57
|
-
store.instance_variable_get(:@client).password.must_equal('')
|
62
|
+
_(store.instance_variable_get(:@client).password).must_equal('')
|
58
63
|
end
|
59
64
|
|
60
65
|
it 'uses nil password' do
|
@@ -64,30 +69,35 @@ describe "Redis::Store::Factory" do
|
|
64
69
|
|
65
70
|
it "disables serialization" do
|
66
71
|
store = Redis::Store::Factory.create :serializer => nil
|
67
|
-
store.instance_variable_get(:@serializer).must_be_nil
|
68
|
-
|
72
|
+
_(store.instance_variable_get(:@serializer)).must_be_nil
|
73
|
+
# `raw` would be removed when `redis-client` is used
|
74
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(true)
|
69
75
|
end
|
70
76
|
|
71
77
|
it "configures pluggable serialization backend" do
|
72
78
|
store = Redis::Store::Factory.create :serializer => JSON
|
73
|
-
store.instance_variable_get(:@serializer).must_equal(JSON)
|
74
|
-
|
79
|
+
_(store.instance_variable_get(:@serializer)).must_equal(JSON)
|
80
|
+
# `raw` would be removed when `redis-client` is used
|
81
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(false)
|
75
82
|
end
|
76
83
|
|
77
84
|
describe "defaults" do
|
78
85
|
it "defaults to localhost if no host specified" do
|
79
86
|
store = Redis::Store::Factory.create
|
80
|
-
|
87
|
+
# `redis.rb` use different default host values in v4 & v5
|
88
|
+
_(store.instance_variable_get(:@client).host).must_match(%r{^127.0.0.1|localhost$})
|
81
89
|
end
|
82
90
|
|
83
91
|
it "defaults to 6379 if no port specified" do
|
84
92
|
store = Redis::Store::Factory.create
|
85
|
-
store.instance_variable_get(:@client).port.must_equal(6379)
|
93
|
+
_(store.instance_variable_get(:@client).port).must_equal(6379)
|
86
94
|
end
|
87
95
|
|
88
96
|
it "defaults to redis:// if no scheme specified" do
|
89
97
|
store = Redis::Store::Factory.create
|
90
|
-
store.instance_variable_get(:@client)
|
98
|
+
client = store.instance_variable_get(:@client)
|
99
|
+
# `redis-client` does NOT have `scheme`
|
100
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('redis')
|
91
101
|
end
|
92
102
|
end
|
93
103
|
|
@@ -102,14 +112,16 @@ describe "Redis::Store::Factory" do
|
|
102
112
|
|
103
113
|
it "disables marshalling and provides deprecation warning" do
|
104
114
|
store = Redis::Store::Factory.create :marshalling => false
|
105
|
-
store.instance_variable_get(:@serializer).must_be_nil
|
106
|
-
|
115
|
+
_(store.instance_variable_get(:@serializer)).must_be_nil
|
116
|
+
# `raw` would be removed when `redis-client` is used
|
117
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(true)
|
107
118
|
end
|
108
119
|
|
109
120
|
it "enables marshalling but provides warning to use :serializer instead" do
|
110
121
|
store = Redis::Store::Factory.create :marshalling => true
|
111
|
-
store.instance_variable_get(:@serializer).must_equal(Marshal)
|
112
|
-
|
122
|
+
_(store.instance_variable_get(:@serializer)).must_equal(Marshal)
|
123
|
+
# `raw` would be removed when `redis-client` is used
|
124
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(false)
|
113
125
|
end
|
114
126
|
|
115
127
|
after do
|
@@ -123,8 +135,8 @@ describe "Redis::Store::Factory" do
|
|
123
135
|
{ :host => "localhost", :port => 6379 },
|
124
136
|
{ :host => "localhost", :port => 6380 }
|
125
137
|
)
|
126
|
-
store.must_be_kind_of(Redis::DistributedStore)
|
127
|
-
store.nodes.map { |node| node.to_s }.must_equal([
|
138
|
+
_(store).must_be_kind_of(Redis::DistributedStore)
|
139
|
+
_(store.nodes.map { |node| node.to_s }).must_equal([
|
128
140
|
"Redis Client connected to localhost:6379 against DB 0",
|
129
141
|
"Redis Client connected to localhost:6380 against DB 0",
|
130
142
|
])
|
@@ -134,62 +146,66 @@ describe "Redis::Store::Factory" do
|
|
134
146
|
describe "when given a String" do
|
135
147
|
it "uses specified host" do
|
136
148
|
store = Redis::Store::Factory.create "redis://127.0.0.1"
|
137
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0")
|
149
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0")
|
138
150
|
end
|
139
151
|
|
140
152
|
it "uses specified port" do
|
141
153
|
store = Redis::Store::Factory.create "redis://127.0.0.1:6380"
|
142
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6380 against DB 0")
|
154
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6380 against DB 0")
|
143
155
|
end
|
144
156
|
|
145
157
|
it "uses specified scheme" do
|
146
158
|
store = Redis::Store::Factory.create "rediss://127.0.0.1:6380"
|
147
|
-
store.instance_variable_get(:@client)
|
159
|
+
client = store.instance_variable_get(:@client)
|
160
|
+
# `redis-client` does NOT have `scheme`
|
161
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('rediss')
|
148
162
|
end
|
149
163
|
|
150
164
|
it "correctly defaults to redis:// when relative scheme specified" do
|
151
165
|
store = Redis::Store::Factory.create "//127.0.0.1:6379"
|
152
|
-
store.instance_variable_get(:@client)
|
166
|
+
client = store.instance_variable_get(:@client)
|
167
|
+
# `redis-client` does NOT have `scheme`
|
168
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('redis')
|
153
169
|
end
|
154
170
|
|
155
171
|
it "uses specified path" do
|
156
172
|
store = Redis::Store::Factory.create "unix:///var/run/redis.sock"
|
157
|
-
store.to_s.must_equal("Redis Client connected to /var/run/redis.sock against DB 0")
|
173
|
+
_(store.to_s).must_equal("Redis Client connected to /var/run/redis.sock against DB 0")
|
158
174
|
end
|
159
175
|
|
160
176
|
it "uses specified db" do
|
161
177
|
store = Redis::Store::Factory.create "redis://127.0.0.1:6380/13"
|
162
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6380 against DB 13")
|
178
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6380 against DB 13")
|
163
179
|
end
|
164
180
|
|
165
181
|
it "uses specified namespace" do
|
166
182
|
store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0/theplaylist"
|
167
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
183
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
168
184
|
end
|
169
185
|
|
170
186
|
it "uses specified via query namespace" do
|
171
187
|
store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0?namespace=theplaylist"
|
172
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
188
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
173
189
|
end
|
174
190
|
|
175
191
|
it "uses specified namespace with path" do
|
176
192
|
store = Redis::Store::Factory.create "unix:///var/run/redis.sock?db=2&namespace=theplaylist"
|
177
|
-
store.to_s.must_equal("Redis Client connected to /var/run/redis.sock against DB 2 with namespace theplaylist")
|
193
|
+
_(store.to_s).must_equal("Redis Client connected to /var/run/redis.sock against DB 2 with namespace theplaylist")
|
178
194
|
end
|
179
195
|
|
180
196
|
it "uses specified password" do
|
181
197
|
store = Redis::Store::Factory.create "redis://:secret@127.0.0.1:6379/0/theplaylist"
|
182
|
-
store.instance_variable_get(:@client).password.must_equal("secret")
|
198
|
+
_(store.instance_variable_get(:@client).password).must_equal("secret")
|
183
199
|
end
|
184
200
|
|
185
201
|
it 'uses specified password with special characters' do
|
186
202
|
store = Redis::Store::Factory.create 'redis://:pwd%40123@127.0.0.1:6379/0/theplaylist'
|
187
|
-
store.instance_variable_get(:@client).password.must_equal('pwd@123')
|
203
|
+
_(store.instance_variable_get(:@client).password).must_equal('pwd@123')
|
188
204
|
end
|
189
205
|
|
190
206
|
it 'uses empty password' do
|
191
207
|
store = Redis::Store::Factory.create 'redis://:@127.0.0.1:6379/0/theplaylist'
|
192
|
-
store.instance_variable_get(:@client).password.must_equal('')
|
208
|
+
_(store.instance_variable_get(:@client).password).must_equal('')
|
193
209
|
end
|
194
210
|
|
195
211
|
it 'uses nil password' do
|
@@ -199,14 +215,14 @@ describe "Redis::Store::Factory" do
|
|
199
215
|
|
200
216
|
it "correctly uses specified ipv6 host" do
|
201
217
|
store = Redis::Store::Factory.create "redis://[::1]:6380"
|
202
|
-
store.to_s.must_equal("Redis Client connected to [::1]:6380 against DB 0")
|
203
|
-
store.instance_variable_get('@options')[:host].must_equal("::1")
|
218
|
+
_(store.to_s).must_equal("Redis Client connected to [::1]:6380 against DB 0")
|
219
|
+
_(store.instance_variable_get('@options')[:host]).must_equal("::1")
|
204
220
|
end
|
205
221
|
|
206
222
|
it "instantiates Redis::DistributedStore" do
|
207
223
|
store = Redis::Store::Factory.create "redis://127.0.0.1:6379", "redis://127.0.0.1:6380"
|
208
|
-
store.must_be_kind_of(Redis::DistributedStore)
|
209
|
-
store.nodes.map { |node| node.to_s }.must_equal([
|
224
|
+
_(store).must_be_kind_of(Redis::DistributedStore)
|
225
|
+
_(store.nodes.map { |node| node.to_s }).must_equal([
|
210
226
|
"Redis Client connected to 127.0.0.1:6379 against DB 0",
|
211
227
|
"Redis Client connected to 127.0.0.1:6380 against DB 0",
|
212
228
|
])
|
@@ -215,7 +231,7 @@ describe "Redis::Store::Factory" do
|
|
215
231
|
|
216
232
|
describe 'when given host Hash and options Hash' do
|
217
233
|
it 'instantiates Redis::Store and merges options' do
|
218
|
-
|
234
|
+
Redis::Store::Factory.create(
|
219
235
|
{ :host => '127.0.0.1', :port => '6379' },
|
220
236
|
{ :namespace => 'theplaylist' }
|
221
237
|
)
|
@@ -227,7 +243,7 @@ describe "Redis::Store::Factory" do
|
|
227
243
|
{ :host => '127.0.0.1', :port => '6380' },
|
228
244
|
{ :namespace => 'theplaylist' }
|
229
245
|
)
|
230
|
-
store.nodes.map { |node| node.to_s }.must_equal([
|
246
|
+
_(store.nodes.map { |node| node.to_s }).must_equal([
|
231
247
|
"Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist",
|
232
248
|
"Redis Client connected to 127.0.0.1:6380 against DB 0 with namespace theplaylist"
|
233
249
|
])
|
@@ -237,20 +253,20 @@ describe "Redis::Store::Factory" do
|
|
237
253
|
describe 'when given host String and options Hash' do
|
238
254
|
it 'instantiates Redis::Store and merges options' do
|
239
255
|
store = Redis::Store::Factory.create "redis://127.0.0.1", :namespace => 'theplaylist'
|
240
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
256
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
241
257
|
end
|
242
258
|
|
243
259
|
it 'instantiates Redis::DistributedStore and merges options' do
|
244
260
|
store = Redis::Store::Factory.create "redis://127.0.0.1:6379", "redis://127.0.0.1:6380", :namespace => 'theplaylist'
|
245
|
-
store.nodes.map { |node| node.to_s }.must_equal([
|
261
|
+
_(store.nodes.map { |node| node.to_s }).must_equal([
|
246
262
|
"Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist",
|
247
263
|
"Redis Client connected to 127.0.0.1:6380 against DB 0 with namespace theplaylist",
|
248
264
|
])
|
249
265
|
end
|
250
266
|
|
251
267
|
it 'instantiates Redis::Store and sets namespace from String' do
|
252
|
-
store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0/theplaylist"
|
253
|
-
store.to_s.must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
268
|
+
store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0/theplaylist"
|
269
|
+
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
254
270
|
end
|
255
271
|
end
|
256
272
|
end
|
@@ -3,7 +3,7 @@ require 'test_helper'
|
|
3
3
|
describe "Redis::Store::Namespace" do
|
4
4
|
def setup
|
5
5
|
@namespace = "theplaylist"
|
6
|
-
@store
|
6
|
+
@store = Redis::Store.new :namespace => @namespace, :serializer => nil
|
7
7
|
@client = @store.instance_variable_get(:@client)
|
8
8
|
@rabbit = "bunny"
|
9
9
|
@default_store = Redis::Store.new
|
@@ -25,12 +25,14 @@ describe "Redis::Store::Namespace" do
|
|
25
25
|
it "only decorates instances that need to be namespaced" do
|
26
26
|
store = Redis::Store.new
|
27
27
|
client = store.instance_variable_get(:@client)
|
28
|
-
|
28
|
+
# `call_v` used since redis-rb 5.0
|
29
|
+
client_call_method_name = client.respond_to?(:call_v) ? :call_v : :call
|
30
|
+
client.expects(client_call_method_name).with([:get, "rabbit"])
|
29
31
|
store.get("rabbit")
|
30
32
|
end
|
31
33
|
|
32
34
|
it "doesn't namespace a key which is already namespaced" do
|
33
|
-
@store.send(:interpolate, "#{@namespace}:rabbit").must_equal("#{@namespace}:rabbit")
|
35
|
+
_(@store.send(:interpolate, "#{@namespace}:rabbit")).must_equal("#{@namespace}:rabbit")
|
34
36
|
end
|
35
37
|
|
36
38
|
it "should only delete namespaced keys" do
|
@@ -38,26 +40,27 @@ describe "Redis::Store::Namespace" do
|
|
38
40
|
@store.set 'def', 'fed'
|
39
41
|
|
40
42
|
@store.flushdb
|
41
|
-
@store.get('def').must_be_nil
|
42
|
-
@default_store.get('abc').must_equal('cba')
|
43
|
+
_(@store.get('def')).must_be_nil
|
44
|
+
_(@default_store.get('abc')).must_equal('cba')
|
43
45
|
end
|
44
46
|
|
45
47
|
it 'should allow to change namespace on the fly' do
|
46
48
|
@default_store.set 'abc', 'cba'
|
47
49
|
@other_store.set 'foo', 'bar'
|
48
50
|
|
49
|
-
@default_store.keys.
|
51
|
+
_(@default_store.keys).must_include('abc')
|
52
|
+
_(@default_store.keys).must_include('other:foo')
|
50
53
|
|
51
54
|
@default_store.with_namespace(@other_namespace) do
|
52
|
-
@default_store.keys.must_equal ['foo']
|
53
|
-
@default_store.get('foo').must_equal('bar')
|
55
|
+
_(@default_store.keys).must_equal ['foo']
|
56
|
+
_(@default_store.get('foo')).must_equal('bar')
|
54
57
|
end
|
55
58
|
end
|
56
59
|
|
57
60
|
it "should not try to delete missing namespaced keys" do
|
58
61
|
empty_store = Redis::Store.new :namespace => 'empty'
|
59
62
|
empty_store.flushdb
|
60
|
-
empty_store.keys.must_be_empty
|
63
|
+
_(empty_store.keys).must_be_empty
|
61
64
|
end
|
62
65
|
|
63
66
|
it "should work with dynamic namespace" do
|
@@ -74,7 +77,7 @@ describe "Redis::Store::Namespace" do
|
|
74
77
|
r2 = dyn_store.get 'key'
|
75
78
|
$ns = "ns1"
|
76
79
|
r1 = dyn_store.get 'key'
|
77
|
-
r1.must_equal('x') && r2.must_equal('y') && r3.must_be_nil
|
80
|
+
_(r1).must_equal('x') && _(r2).must_equal('y') && _(r3).must_be_nil
|
78
81
|
end
|
79
82
|
|
80
83
|
it "namespaces setex and ttl" do
|
@@ -82,45 +85,49 @@ describe "Redis::Store::Namespace" do
|
|
82
85
|
@other_store.flushdb
|
83
86
|
|
84
87
|
@store.setex('foo', 30, 'bar')
|
85
|
-
@store.ttl('foo').must_be_close_to(30)
|
86
|
-
@store.get('foo').must_equal('bar')
|
88
|
+
_(@store.ttl('foo')).must_be_close_to(30)
|
89
|
+
_(@store.get('foo')).must_equal('bar')
|
87
90
|
|
88
|
-
@other_store.ttl('foo').must_equal(-2)
|
89
|
-
@other_store.get('foo').must_be_nil
|
91
|
+
_(@other_store.ttl('foo')).must_equal(-2)
|
92
|
+
_(@other_store.get('foo')).must_be_nil
|
90
93
|
end
|
91
94
|
|
92
95
|
describe 'method calls' do
|
93
96
|
let(:store) { Redis::Store.new :namespace => @namespace, :serializer => nil }
|
94
97
|
let(:client) { store.instance_variable_get(:@client) }
|
98
|
+
let(:client_call_method_name) do
|
99
|
+
# `call_v` used since redis-rb 5.0
|
100
|
+
client.respond_to?(:call_v) ? :call_v : :call
|
101
|
+
end
|
95
102
|
|
96
103
|
it "should namespace get" do
|
97
|
-
client.expects(
|
104
|
+
client.expects(client_call_method_name).with([:get, "#{@namespace}:rabbit"]).once
|
98
105
|
store.get("rabbit")
|
99
106
|
end
|
100
107
|
|
101
108
|
it "should namespace set" do
|
102
|
-
client.expects(
|
109
|
+
client.expects(client_call_method_name).with([:set, "#{@namespace}:rabbit", @rabbit])
|
103
110
|
store.set "rabbit", @rabbit
|
104
111
|
end
|
105
112
|
|
106
113
|
it "should namespace setnx" do
|
107
|
-
client.expects(
|
114
|
+
client.expects(client_call_method_name).with([:setnx, "#{@namespace}:rabbit", @rabbit])
|
108
115
|
store.setnx "rabbit", @rabbit
|
109
116
|
end
|
110
117
|
|
111
118
|
it "should namespace del with single key" do
|
112
|
-
client.expects(
|
119
|
+
client.expects(client_call_method_name).with([:del, "#{@namespace}:rabbit"])
|
113
120
|
store.del "rabbit"
|
114
121
|
end
|
115
122
|
|
116
123
|
it "should namespace del with multiple keys" do
|
117
|
-
client.expects(
|
124
|
+
client.expects(client_call_method_name).with([:del, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
|
118
125
|
store.del "rabbit", "white_rabbit"
|
119
126
|
end
|
120
127
|
|
121
128
|
it "should namespace keys" do
|
122
129
|
store.set "rabbit", @rabbit
|
123
|
-
store.keys("rabb*").must_equal [ "rabbit" ]
|
130
|
+
_(store.keys("rabb*")).must_equal [ "rabbit" ]
|
124
131
|
end
|
125
132
|
|
126
133
|
it "should namespace scan when a pattern is given" do
|
@@ -131,173 +138,179 @@ describe "Redis::Store::Namespace" do
|
|
131
138
|
cursor, matched_keys = store.scan(cursor, match: "rabb*")
|
132
139
|
keys = keys.concat(matched_keys) unless matched_keys.empty?
|
133
140
|
end until cursor == "0"
|
134
|
-
keys.must_equal [ "rabbit" ]
|
141
|
+
_(keys).must_equal [ "rabbit" ]
|
135
142
|
end
|
136
143
|
|
137
144
|
it "should namespace exists" do
|
138
|
-
client.expects(
|
145
|
+
client.expects(client_call_method_name).with([:exists, "#{@namespace}:rabbit"])
|
139
146
|
store.exists "rabbit"
|
140
147
|
end
|
141
148
|
|
142
149
|
it "should namespace incrby" do
|
143
|
-
client.expects(
|
150
|
+
client.expects(client_call_method_name).with([:incrby, "#{@namespace}:counter", 1])
|
144
151
|
store.incrby "counter", 1
|
145
152
|
end
|
146
153
|
|
147
154
|
it "should namespace decrby" do
|
148
|
-
client.expects(
|
155
|
+
client.expects(client_call_method_name).with([:decrby, "#{@namespace}:counter", 1])
|
149
156
|
store.decrby "counter", 1
|
150
157
|
end
|
151
158
|
|
152
159
|
it "should namespace mget" do
|
153
|
-
client.expects(
|
160
|
+
client.expects(client_call_method_name).with([:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"]).returns(%w[ foo bar ])
|
154
161
|
store.mget "rabbit", "white_rabbit" do |result|
|
155
|
-
result.must_equal(%w[ foo bar ])
|
162
|
+
_(result).must_equal(%w[ foo bar ])
|
156
163
|
end
|
157
164
|
end
|
158
165
|
|
159
166
|
it "should namespace mapped_mget" do
|
160
|
-
client.
|
167
|
+
if client.respond_to?(:process, true)
|
168
|
+
# Redis < 5.0 uses `#process`
|
169
|
+
client.expects(:process).with([[:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"]]).returns(%w[ foo bar ])
|
170
|
+
else
|
171
|
+
# Redis 5.x calls `#ensure_connected` (private)
|
172
|
+
client.send(:ensure_connected).expects(:call).returns(%w[ foo bar ])
|
173
|
+
end
|
161
174
|
result = store.mapped_mget "rabbit", "white_rabbit"
|
162
|
-
result.keys.must_equal %w[ rabbit white_rabbit ]
|
163
|
-
result["rabbit"].must_equal "foo"
|
164
|
-
result["white_rabbit"].must_equal "bar"
|
175
|
+
_(result.keys).must_equal %w[ rabbit white_rabbit ]
|
176
|
+
_(result["rabbit"]).must_equal "foo"
|
177
|
+
_(result["white_rabbit"]).must_equal "bar"
|
165
178
|
end
|
166
179
|
|
167
180
|
it "should namespace expire" do
|
168
|
-
client.expects(
|
181
|
+
client.expects(client_call_method_name).with([:expire, "#{@namespace}:rabbit", 60]).once
|
169
182
|
store.expire("rabbit", 60)
|
170
183
|
end
|
171
184
|
|
172
185
|
it "should namespace ttl" do
|
173
|
-
client.expects(
|
186
|
+
client.expects(client_call_method_name).with([:ttl, "#{@namespace}:rabbit"]).once
|
174
187
|
store.ttl("rabbit")
|
175
188
|
end
|
176
189
|
|
177
190
|
it "should namespace watch" do
|
178
|
-
client.expects(
|
191
|
+
client.expects(client_call_method_name).with([:watch, "#{@namespace}:rabbit"]).once
|
179
192
|
store.watch("rabbit")
|
180
193
|
end
|
181
194
|
|
182
195
|
it "wraps flushdb with appropriate KEYS * calls" do
|
183
|
-
client.expects(
|
184
|
-
client.expects(
|
185
|
-
client.expects(
|
196
|
+
client.expects(client_call_method_name).with([:flushdb]).never
|
197
|
+
client.expects(client_call_method_name).with([:keys, "#{@namespace}:*"]).once.returns(["rabbit"])
|
198
|
+
client.expects(client_call_method_name).with([:del, "#{@namespace}:rabbit"]).once
|
186
199
|
store.flushdb
|
187
200
|
end
|
188
201
|
|
189
202
|
it "skips flushdb wrapping if the namespace is nil" do
|
190
|
-
client.expects(
|
191
|
-
client.expects(
|
203
|
+
client.expects(client_call_method_name).with([:flushdb])
|
204
|
+
client.expects(client_call_method_name).with([:keys]).never
|
192
205
|
store.with_namespace(nil) do
|
193
206
|
store.flushdb
|
194
207
|
end
|
195
208
|
end
|
196
209
|
|
197
210
|
it "should namespace hdel" do
|
198
|
-
client.expects(
|
211
|
+
client.expects(client_call_method_name).with([:hdel, "#{@namespace}:rabbit", "key1", "key2"]).once
|
199
212
|
store.hdel("rabbit", "key1", "key2")
|
200
213
|
end
|
201
214
|
|
202
215
|
it "should namespace hget" do
|
203
|
-
client.expects(
|
216
|
+
client.expects(client_call_method_name).with([:hget, "#{@namespace}:rabbit", "key"]).once
|
204
217
|
store.hget("rabbit", "key")
|
205
218
|
end
|
206
219
|
|
207
220
|
it "should namespace hgetall" do
|
208
|
-
client.expects(
|
221
|
+
client.expects(client_call_method_name).with([:hgetall, "#{@namespace}:rabbit"]).once
|
209
222
|
store.hgetall("rabbit")
|
210
223
|
end
|
211
224
|
|
212
225
|
it "should namespace hexists" do
|
213
|
-
client.expects(
|
214
|
-
|
226
|
+
client.expects(client_call_method_name).with([:hexists, "#{@namespace}:rabbit", "key"]).once
|
227
|
+
store.hexists("rabbit", "key")
|
215
228
|
end
|
216
229
|
|
217
230
|
it "should namespace hincrby" do
|
218
|
-
client.expects(
|
231
|
+
client.expects(client_call_method_name).with([:hincrby, "#{@namespace}:rabbit", "key", 1]).once
|
219
232
|
store.hincrby("rabbit", "key", 1)
|
220
233
|
end
|
221
234
|
|
222
235
|
it "should namespace hincrbyfloat" do
|
223
|
-
client.expects(
|
224
|
-
store.
|
236
|
+
client.expects(client_call_method_name).with([:hincrbyfloat, "#{@namespace}:rabbit", "key", 1.5]).once
|
237
|
+
store.hincrbyfloat("rabbit", "key", 1.5)
|
225
238
|
end
|
226
239
|
|
227
240
|
it "should namespace hkeys" do
|
228
|
-
client.expects(
|
241
|
+
client.expects(client_call_method_name).with([:hkeys, "#{@namespace}:rabbit"])
|
229
242
|
store.hkeys("rabbit")
|
230
243
|
end
|
231
244
|
|
232
245
|
it "should namespace hlen" do
|
233
|
-
client.expects(
|
246
|
+
client.expects(client_call_method_name).with([:hlen, "#{@namespace}:rabbit"])
|
234
247
|
store.hlen("rabbit")
|
235
248
|
end
|
236
249
|
|
237
250
|
it "should namespace hmget" do
|
238
|
-
client.expects(
|
251
|
+
client.expects(client_call_method_name).with([:hmget, "#{@namespace}:rabbit", "key1", "key2"])
|
239
252
|
store.hmget("rabbit", "key1", "key2")
|
240
253
|
end
|
241
254
|
|
242
255
|
it "should namespace hmset" do
|
243
|
-
client.expects(
|
256
|
+
client.expects(client_call_method_name).with([:hmset, "#{@namespace}:rabbit", "key", @rabbit])
|
244
257
|
store.hmset("rabbit", "key", @rabbit)
|
245
258
|
end
|
246
259
|
|
247
260
|
it "should namespace hset" do
|
248
|
-
client.expects(
|
261
|
+
client.expects(client_call_method_name).with([:hset, "#{@namespace}:rabbit", "key", @rabbit])
|
249
262
|
store.hset("rabbit", "key", @rabbit)
|
250
263
|
end
|
251
264
|
|
252
265
|
it "should namespace hsetnx" do
|
253
|
-
client.expects(
|
266
|
+
client.expects(client_call_method_name).with([:hsetnx, "#{@namespace}:rabbit", "key", @rabbit])
|
254
267
|
store.hsetnx("rabbit", "key", @rabbit)
|
255
268
|
end
|
256
269
|
|
257
270
|
it "should namespace hvals" do
|
258
|
-
client.expects(
|
271
|
+
client.expects(client_call_method_name).with([:hvals, "#{@namespace}:rabbit"])
|
259
272
|
store.hvals("rabbit")
|
260
273
|
end
|
261
274
|
|
262
275
|
it "should namespace hscan" do
|
263
|
-
client.expects(
|
276
|
+
client.expects(client_call_method_name).with([:hscan, "#{@namespace}:rabbit", 0])
|
264
277
|
store.hscan("rabbit", 0)
|
265
278
|
end
|
266
279
|
|
267
280
|
it "should namespace hscan_each with block" do
|
268
|
-
client.
|
269
|
-
client.expects(
|
281
|
+
client.public_send(client_call_method_name, [:hset, "#{@namespace}:rabbit", "key1", @rabbit])
|
282
|
+
client.expects(client_call_method_name).with([:hscan, "#{@namespace}:rabbit", 0]).returns(["0", ["key1"]])
|
270
283
|
results = []
|
271
284
|
store.hscan_each("rabbit") do |key|
|
272
285
|
results << key
|
273
286
|
end
|
274
|
-
results.must_equal(["key1"])
|
287
|
+
_(results).must_equal(["key1"])
|
275
288
|
end
|
276
289
|
|
277
290
|
it "should namespace hscan_each without block" do
|
278
|
-
client.
|
279
|
-
client.expects(
|
291
|
+
client.public_send(client_call_method_name, [:hset, "#{@namespace}:rabbit", "key1", @rabbit])
|
292
|
+
client.expects(client_call_method_name).with([:hscan, "#{@namespace}:rabbit", 0]).returns(["0", ["key1"]])
|
280
293
|
results = store.hscan_each("rabbit").to_a
|
281
|
-
results.must_equal(["key1"])
|
294
|
+
_(results).must_equal(["key1"])
|
282
295
|
end
|
283
296
|
|
284
297
|
it "should namespace zincrby" do
|
285
|
-
client.expects(
|
298
|
+
client.expects(client_call_method_name).with([:zincrby, "#{@namespace}:rabbit", 1.0, "member"])
|
286
299
|
store.zincrby("rabbit", 1.0, "member")
|
287
300
|
end
|
288
301
|
|
289
302
|
it "should namespace zscore" do
|
290
|
-
client.expects(
|
303
|
+
client.expects(client_call_method_name).with([:zscore, "#{@namespace}:rabbit", "member"])
|
291
304
|
store.zscore("rabbit", "member")
|
292
305
|
end
|
293
306
|
|
294
307
|
it "should namespace zadd" do
|
295
|
-
client.expects(
|
308
|
+
client.expects(client_call_method_name).with([:zadd, "#{@namespace}:rabbit", 1.0, "member"])
|
296
309
|
store.zadd("rabbit", 1.0, "member")
|
297
310
|
end
|
298
311
|
|
299
312
|
it "should namespace zrem" do
|
300
|
-
client.expects(
|
313
|
+
client.expects(client_call_method_name).with([:zrem, "#{@namespace}:rabbit", "member"])
|
301
314
|
store.zrem("rabbit", "member")
|
302
315
|
end
|
303
316
|
end
|