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