redis-namespace 1.6.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +17 -16
- data/README.md +22 -18
- data/lib/redis/namespace/version.rb +1 -1
- data/lib/redis/namespace.rb +87 -32
- data/spec/deprecation_spec.rb +4 -4
- data/spec/redis_spec.rb +336 -186
- data/spec/spec_helper.rb +5 -0
- metadata +38 -18
data/spec/redis_spec.rb
CHANGED
@@ -3,54 +3,60 @@
|
|
3
3
|
require File.dirname(__FILE__) + '/spec_helper'
|
4
4
|
|
5
5
|
describe "redis" do
|
6
|
-
@redis_version = Gem::Version.new(Redis.
|
6
|
+
@redis_version = Gem::Version.new(Redis.new.info["redis_version"])
|
7
7
|
let(:redis_client) { @redis.respond_to?(:_client) ? @redis._client : @redis.client}
|
8
8
|
|
9
|
-
before(:
|
9
|
+
before(:each) do
|
10
10
|
# use database 15 for testing so we dont accidentally step on your real data
|
11
11
|
@redis = Redis.new :db => 15
|
12
|
-
end
|
13
|
-
|
14
|
-
before(:each) do
|
15
|
-
@namespaced = Redis::Namespace.new(:ns, :redis => @redis)
|
16
12
|
@redis.flushdb
|
13
|
+
@namespaced = Redis::Namespace.new(:ns, :redis => @redis)
|
17
14
|
@redis.set('foo', 'bar')
|
18
15
|
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
after(:all) do
|
25
|
-
@redis.quit
|
17
|
+
# redis-rb 3.3.4+
|
18
|
+
it "should inject :namespace into connection info" do
|
19
|
+
info = @redis.connection.merge(:namespace => :ns)
|
20
|
+
expect(@namespaced.connection).to eq(info)
|
26
21
|
end
|
27
22
|
|
28
23
|
it "proxies `client` to the _client and deprecated" do
|
29
|
-
@namespaced.client.
|
24
|
+
expect(@namespaced.client).to eq(redis_client)
|
30
25
|
end
|
31
26
|
|
32
27
|
it "proxies `_client` to the _client" do
|
33
|
-
@namespaced._client.
|
28
|
+
expect(@namespaced._client).to eq(redis_client)
|
34
29
|
end
|
35
30
|
|
36
31
|
it "should be able to use a namespace" do
|
37
|
-
@namespaced.get('foo').
|
32
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
38
33
|
@namespaced.set('foo', 'chris')
|
39
|
-
@namespaced.get('foo').
|
34
|
+
expect(@namespaced.get('foo')).to eq('chris')
|
40
35
|
@redis.set('foo', 'bob')
|
41
|
-
@redis.get('foo').
|
36
|
+
expect(@redis.get('foo')).to eq('bob')
|
42
37
|
|
43
38
|
@namespaced.incrby('counter', 2)
|
44
|
-
@namespaced.get('counter').to_i.
|
45
|
-
@redis.get('counter').
|
46
|
-
@namespaced.type('counter').
|
39
|
+
expect(@namespaced.get('counter').to_i).to eq(2)
|
40
|
+
expect(@redis.get('counter')).to eq(nil)
|
41
|
+
expect(@namespaced.type('counter')).to eq('string')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should work with Proc namespaces" do
|
45
|
+
namespace = Proc.new { :dynamic_ns }
|
46
|
+
namespaced = Redis::Namespace.new(namespace, redis: @redis)
|
47
|
+
|
48
|
+
expect(namespaced.get('foo')).to eq(nil)
|
49
|
+
namespaced.set('foo', 'chris')
|
50
|
+
expect(namespaced.get('foo')).to eq('chris')
|
51
|
+
@redis.set('foo', 'bob')
|
52
|
+
expect(@redis.get('foo')).to eq('bob')
|
47
53
|
end
|
48
54
|
|
49
55
|
context 'when sending capital commands (issue 68)' do
|
50
56
|
it 'should be able to use a namespace' do
|
51
57
|
@namespaced.send('SET', 'fubar', 'quux')
|
52
|
-
@redis.get('fubar').
|
53
|
-
@namespaced.get('fubar').
|
58
|
+
expect(@redis.get('fubar')).to be_nil
|
59
|
+
expect(@namespaced.get('fubar')).to eq 'quux'
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
@@ -58,10 +64,10 @@ describe "redis" do
|
|
58
64
|
@namespaced.rpush "foo", "string"
|
59
65
|
@namespaced.rpush "foo", "ns:string"
|
60
66
|
@namespaced.rpush "foo", "string_no_timeout"
|
61
|
-
@namespaced.blpop("foo", 1).
|
62
|
-
@namespaced.blpop("foo", 1).
|
63
|
-
@namespaced.blpop("foo").
|
64
|
-
@namespaced.blpop("foo", 1).
|
67
|
+
expect(@namespaced.blpop("foo", 1)).to eq(["foo", "string"])
|
68
|
+
expect(@namespaced.blpop("foo", 1)).to eq(["foo", "ns:string"])
|
69
|
+
expect(@namespaced.blpop("foo")).to eq(["foo", "string_no_timeout"])
|
70
|
+
expect(@namespaced.blpop("foo", 1)).to eq(nil)
|
65
71
|
end
|
66
72
|
|
67
73
|
it "should be able to use a namespace with del" do
|
@@ -69,125 +75,168 @@ describe "redis" do
|
|
69
75
|
@namespaced.set('bar', 2000)
|
70
76
|
@namespaced.set('baz', 3000)
|
71
77
|
@namespaced.del 'foo'
|
72
|
-
@namespaced.get('foo').
|
78
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
73
79
|
@namespaced.del 'bar', 'baz'
|
74
|
-
@namespaced.get('bar').
|
75
|
-
@namespaced.get('baz').
|
80
|
+
expect(@namespaced.get('bar')).to eq(nil)
|
81
|
+
expect(@namespaced.get('baz')).to eq(nil)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be able to use a namespace with unlink" do
|
85
|
+
@namespaced.set('foo', 1000)
|
86
|
+
@namespaced.set('bar', 2000)
|
87
|
+
@namespaced.set('baz', 3000)
|
88
|
+
@namespaced.unlink 'foo'
|
89
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
90
|
+
@namespaced.unlink 'bar', 'baz'
|
91
|
+
expect(@namespaced.get('bar')).to eq(nil)
|
92
|
+
expect(@namespaced.get('baz')).to eq(nil)
|
76
93
|
end
|
77
94
|
|
78
95
|
it 'should be able to use a namespace with append' do
|
79
96
|
@namespaced.set('foo', 'bar')
|
80
|
-
@namespaced.append('foo','n').
|
81
|
-
@namespaced.get('foo').
|
82
|
-
@redis.get('foo').
|
97
|
+
expect(@namespaced.append('foo','n')).to eq(4)
|
98
|
+
expect(@namespaced.get('foo')).to eq('barn')
|
99
|
+
expect(@redis.get('foo')).to eq('bar')
|
83
100
|
end
|
84
101
|
|
85
102
|
it 'should be able to use a namespace with brpoplpush' do
|
86
103
|
@namespaced.lpush('foo','bar')
|
87
|
-
@namespaced.brpoplpush('foo','bar',0).
|
88
|
-
@namespaced.lrange('foo',0,-1).
|
89
|
-
@namespaced.lrange('bar',0,-1).
|
104
|
+
expect(@namespaced.brpoplpush('foo','bar',0)).to eq('bar')
|
105
|
+
expect(@namespaced.lrange('foo',0,-1)).to eq([])
|
106
|
+
expect(@namespaced.lrange('bar',0,-1)).to eq(['bar'])
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should be able to use a namespace with getex" do
|
110
|
+
expect(@namespaced.set('mykey', 'Hello')).to eq('OK')
|
111
|
+
expect(@namespaced.getex('mykey', ex: 50)).to eq('Hello')
|
112
|
+
expect(@namespaced.get('mykey')).to eq('Hello')
|
113
|
+
expect(@namespaced.ttl('mykey')).to eq(50)
|
90
114
|
end
|
91
115
|
|
92
116
|
it 'should be able to use a namespace with getbit' do
|
93
117
|
@namespaced.set('foo','bar')
|
94
|
-
@namespaced.getbit('foo',1).
|
118
|
+
expect(@namespaced.getbit('foo',1)).to eq(1)
|
95
119
|
end
|
96
120
|
|
97
121
|
it 'should be able to use a namespace with getrange' do
|
98
122
|
@namespaced.set('foo','bar')
|
99
|
-
@namespaced.getrange('foo',0,-1).
|
123
|
+
expect(@namespaced.getrange('foo',0,-1)).to eq('bar')
|
100
124
|
end
|
101
125
|
|
102
126
|
it 'should be able to use a namespace with linsert' do
|
103
127
|
@namespaced.rpush('foo','bar')
|
104
128
|
@namespaced.rpush('foo','barn')
|
105
129
|
@namespaced.rpush('foo','bart')
|
106
|
-
@namespaced.linsert('foo','BEFORE','barn','barf').
|
107
|
-
@namespaced.lrange('foo',0,-1).
|
130
|
+
expect(@namespaced.linsert('foo','BEFORE','barn','barf')).to eq(4)
|
131
|
+
expect(@namespaced.lrange('foo',0,-1)).to eq(['bar','barf','barn','bart'])
|
108
132
|
end
|
109
133
|
|
110
134
|
it 'should be able to use a namespace with lpushx' do
|
111
|
-
@namespaced.lpushx('foo','bar').
|
135
|
+
expect(@namespaced.lpushx('foo','bar')).to eq(0)
|
112
136
|
@namespaced.lpush('foo','boo')
|
113
|
-
@namespaced.lpushx('foo','bar').
|
114
|
-
@namespaced.lrange('foo',0,-1).
|
137
|
+
expect(@namespaced.lpushx('foo','bar')).to eq(2)
|
138
|
+
expect(@namespaced.lrange('foo',0,-1)).to eq(['bar','boo'])
|
115
139
|
end
|
116
140
|
|
117
141
|
it 'should be able to use a namespace with rpushx' do
|
118
|
-
@namespaced.rpushx('foo','bar').
|
142
|
+
expect(@namespaced.rpushx('foo','bar')).to eq(0)
|
119
143
|
@namespaced.lpush('foo','boo')
|
120
|
-
@namespaced.rpushx('foo','bar').
|
121
|
-
@namespaced.lrange('foo',0,-1).
|
144
|
+
expect(@namespaced.rpushx('foo','bar')).to eq(2)
|
145
|
+
expect(@namespaced.lrange('foo',0,-1)).to eq(['boo','bar'])
|
122
146
|
end
|
123
147
|
|
124
148
|
it 'should be able to use a namespace with setbit' do
|
125
149
|
@namespaced.setbit('virgin_key', 1, 1)
|
126
|
-
@namespaced.exists('virgin_key').
|
127
|
-
@namespaced.get('virgin_key').
|
150
|
+
expect(@namespaced.exists?('virgin_key')).to be true
|
151
|
+
expect(@namespaced.get('virgin_key')).to eq(@namespaced.getrange('virgin_key',0,-1))
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should be able to use a namespace with exists' do
|
155
|
+
@namespaced.set('foo', 1000)
|
156
|
+
@namespaced.set('bar', 2000)
|
157
|
+
expect(@namespaced.exists('foo', 'bar')).to eq(2)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should be able to use a namespace with exists?' do
|
161
|
+
@namespaced.set('foo', 1000)
|
162
|
+
@namespaced.set('bar', 2000)
|
163
|
+
expect(@namespaced.exists?('does_not_exist', 'bar')).to eq(true)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should be able to use a namespace with bitpos' do
|
167
|
+
@namespaced.setbit('bit_map', 42, 1)
|
168
|
+
expect(@namespaced.bitpos('bit_map', 0)).to eq(0)
|
169
|
+
expect(@namespaced.bitpos('bit_map', 1)).to eq(42)
|
128
170
|
end
|
129
171
|
|
130
172
|
it 'should be able to use a namespace with setrange' do
|
131
173
|
@namespaced.setrange('foo', 0, 'bar')
|
132
|
-
@namespaced.get('foo').
|
174
|
+
expect(@namespaced.get('foo')).to eq('bar')
|
133
175
|
|
134
176
|
@namespaced.setrange('bar', 2, 'foo')
|
135
|
-
@namespaced.get('bar').
|
177
|
+
expect(@namespaced.get('bar')).to eq("\000\000foo")
|
136
178
|
end
|
137
179
|
|
138
180
|
it "should be able to use a namespace with mget" do
|
139
181
|
@namespaced.set('foo', 1000)
|
140
182
|
@namespaced.set('bar', 2000)
|
141
|
-
@namespaced.mapped_mget('foo', 'bar').
|
142
|
-
@namespaced.mapped_mget('foo', 'baz', 'bar').
|
183
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
|
184
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
|
143
185
|
end
|
144
186
|
|
145
187
|
it "should be able to use a namespace with mset" do
|
146
188
|
@namespaced.mset('foo', '1000', 'bar', '2000')
|
147
|
-
@namespaced.mapped_mget('foo', 'bar').
|
148
|
-
@namespaced.mapped_mget('foo', 'baz', 'bar').
|
189
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
|
190
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
|
191
|
+
|
149
192
|
@namespaced.mapped_mset('foo' => '3000', 'bar' => '5000')
|
150
|
-
@namespaced.mapped_mget('foo', 'bar').
|
151
|
-
@namespaced.mapped_mget('foo', 'baz', 'bar').
|
193
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000' })
|
194
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
|
195
|
+
|
196
|
+
@namespaced.mset(['foo', '4000'], ['baz', '6000'])
|
197
|
+
expect(@namespaced.mapped_mget('foo', 'bar', 'baz')).to eq({ 'foo' => '4000', 'bar' => '5000', 'baz' => '6000' })
|
152
198
|
end
|
153
199
|
|
154
200
|
it "should be able to use a namespace with msetnx" do
|
155
201
|
@namespaced.msetnx('foo', '1000', 'bar', '2000')
|
156
|
-
@namespaced.mapped_mget('foo', 'bar').
|
157
|
-
@namespaced.mapped_mget('foo', 'baz', 'bar').
|
202
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
|
203
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
|
204
|
+
|
205
|
+
@namespaced.msetnx(['baz', '4000'])
|
206
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => '4000'})
|
158
207
|
end
|
159
208
|
|
160
209
|
it "should be able to use a namespace with mapped_msetnx" do
|
161
210
|
@namespaced.set('foo','1')
|
162
|
-
@namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000').
|
163
|
-
@namespaced.mapped_mget('foo', 'bar').
|
164
|
-
@namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000').
|
165
|
-
@namespaced.mapped_mget('foo', 'bar').
|
211
|
+
expect(@namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000')).to be false
|
212
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1', 'bar' => nil })
|
213
|
+
expect(@namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000')).to be true
|
214
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1', 'bar' => '2000' })
|
166
215
|
end
|
167
216
|
|
168
217
|
it "should be able to use a namespace with hashes" do
|
169
218
|
@namespaced.hset('foo', 'key', 'value')
|
170
219
|
@namespaced.hset('foo', 'key1', 'value1')
|
171
|
-
@namespaced.hget('foo', 'key').
|
172
|
-
@namespaced.hgetall('foo').
|
173
|
-
@namespaced.hlen('foo').
|
174
|
-
@namespaced.hkeys('foo').
|
220
|
+
expect(@namespaced.hget('foo', 'key')).to eq('value')
|
221
|
+
expect(@namespaced.hgetall('foo')).to eq({'key' => 'value', 'key1' => 'value1'})
|
222
|
+
expect(@namespaced.hlen('foo')).to eq(2)
|
223
|
+
expect(@namespaced.hkeys('foo')).to eq(['key', 'key1'])
|
175
224
|
@namespaced.hmset('bar', 'key', 'value', 'key1', 'value1')
|
176
225
|
@namespaced.hmget('bar', 'key', 'key1')
|
177
226
|
@namespaced.hmset('bar', 'a_number', 1)
|
178
|
-
@namespaced.hmget('bar', 'a_number').
|
227
|
+
expect(@namespaced.hmget('bar', 'a_number')).to eq(['1'])
|
179
228
|
@namespaced.hincrby('bar', 'a_number', 3)
|
180
|
-
@namespaced.hmget('bar', 'a_number').
|
181
|
-
@namespaced.hgetall('bar').
|
182
|
-
|
183
|
-
@namespaced.hsetnx('foonx','nx',10).
|
184
|
-
@namespaced.hsetnx('foonx','nx',12).
|
185
|
-
@namespaced.hget('foonx','nx').
|
186
|
-
@namespaced.hkeys('foonx').
|
187
|
-
@namespaced.hvals('foonx').
|
229
|
+
expect(@namespaced.hmget('bar', 'a_number')).to eq(['4'])
|
230
|
+
expect(@namespaced.hgetall('bar')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
|
231
|
+
|
232
|
+
expect(@namespaced.hsetnx('foonx','nx',10)).to be true
|
233
|
+
expect(@namespaced.hsetnx('foonx','nx',12)).to be false
|
234
|
+
expect(@namespaced.hget('foonx','nx')).to eq("10")
|
235
|
+
expect(@namespaced.hkeys('foonx')).to eq(%w{ nx })
|
236
|
+
expect(@namespaced.hvals('foonx')).to eq(%w{ 10 })
|
188
237
|
@namespaced.mapped_hmset('baz', {'key' => 'value', 'key1' => 'value1', 'a_number' => 4})
|
189
|
-
@namespaced.mapped_hmget('baz', 'key', 'key1', 'a_number').
|
190
|
-
@namespaced.hgetall('baz').
|
238
|
+
expect(@namespaced.mapped_hmget('baz', 'key', 'key1', 'a_number')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
|
239
|
+
expect(@namespaced.hgetall('baz')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
|
191
240
|
end
|
192
241
|
|
193
242
|
it "should properly intersect three sets" do
|
@@ -198,7 +247,7 @@ describe "redis" do
|
|
198
247
|
@namespaced.sadd('bar', 3)
|
199
248
|
@namespaced.sadd('bar', 4)
|
200
249
|
@namespaced.sadd('baz', 3)
|
201
|
-
@namespaced.sinter('foo', 'bar', 'baz').
|
250
|
+
expect(@namespaced.sinter('foo', 'bar', 'baz')).to eq(%w( 3 ))
|
202
251
|
end
|
203
252
|
|
204
253
|
it "should properly union two sets" do
|
@@ -207,7 +256,7 @@ describe "redis" do
|
|
207
256
|
@namespaced.sadd('bar', 2)
|
208
257
|
@namespaced.sadd('bar', 3)
|
209
258
|
@namespaced.sadd('bar', 4)
|
210
|
-
@namespaced.sunion('foo', 'bar').sort.
|
259
|
+
expect(@namespaced.sunion('foo', 'bar').sort).to eq(%w( 1 2 3 4 ))
|
211
260
|
end
|
212
261
|
|
213
262
|
it "should properly union two sorted sets with options" do
|
@@ -216,8 +265,8 @@ describe "redis" do
|
|
216
265
|
@namespaced.zadd('sort2', 2, 2)
|
217
266
|
@namespaced.zadd('sort2', 3, 3)
|
218
267
|
@namespaced.zadd('sort2', 4, 4)
|
219
|
-
@namespaced.zunionstore('union', ['sort1', 'sort2'], :
|
220
|
-
@namespaced.zrevrange('union', 0, -1).
|
268
|
+
@namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1])
|
269
|
+
expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
|
221
270
|
end
|
222
271
|
|
223
272
|
it "should properly union two sorted sets without options" do
|
@@ -227,7 +276,7 @@ describe "redis" do
|
|
227
276
|
@namespaced.zadd('sort2', 3, 3)
|
228
277
|
@namespaced.zadd('sort2', 4, 4)
|
229
278
|
@namespaced.zunionstore('union', ['sort1', 'sort2'])
|
230
|
-
@namespaced.zrevrange('union', 0, -1).
|
279
|
+
expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 4 2 3 1 ))
|
231
280
|
end
|
232
281
|
|
233
282
|
it "should properly intersect two sorted sets without options" do
|
@@ -242,7 +291,7 @@ describe "redis" do
|
|
242
291
|
@namespaced.zinterstore('inter', ['food', 'color'])
|
243
292
|
|
244
293
|
inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
|
245
|
-
inter_values.
|
294
|
+
expect(inter_values).to match_array([['orange', 3.0], ['eggplant', 7.0]])
|
246
295
|
end
|
247
296
|
|
248
297
|
it "should properly intersect two sorted sets with options" do
|
@@ -257,7 +306,37 @@ describe "redis" do
|
|
257
306
|
@namespaced.zinterstore('inter', ['food', 'color'], :aggregate => "min")
|
258
307
|
|
259
308
|
inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
|
260
|
-
inter_values.
|
309
|
+
expect(inter_values).to match_array([['orange', 1.0], ['eggplant', 3.0]])
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should return lexicographical range for sorted set" do
|
313
|
+
@namespaced.zadd('food', 0, 'orange')
|
314
|
+
@namespaced.zadd('food', 0, 'banana')
|
315
|
+
@namespaced.zadd('food', 0, 'eggplant')
|
316
|
+
|
317
|
+
values = @namespaced.zrangebylex('food', '[b', '(o')
|
318
|
+
expect(values).to match_array(['banana', 'eggplant'])
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should return the number of elements removed from the set" do
|
322
|
+
@namespaced.zadd('food', 0, 'orange')
|
323
|
+
@namespaced.zadd('food', 0, 'banana')
|
324
|
+
@namespaced.zadd('food', 0, 'eggplant')
|
325
|
+
|
326
|
+
removed = @namespaced.zremrangebylex('food', '[b', '(o')
|
327
|
+
expect(removed).to eq(2)
|
328
|
+
|
329
|
+
values = @namespaced.zrange('food', 0, -1)
|
330
|
+
expect(values).to eq(['orange'])
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should return reverce lexicographical range for sorted set" do
|
334
|
+
@namespaced.zadd('food', 0, 'orange')
|
335
|
+
@namespaced.zadd('food', 0, 'banana')
|
336
|
+
@namespaced.zadd('food', 0, 'eggplant')
|
337
|
+
|
338
|
+
values = @namespaced.zrevrangebylex('food', '(o', '[b')
|
339
|
+
expect(values).to match_array(['banana', 'eggplant'])
|
261
340
|
end
|
262
341
|
|
263
342
|
it "should add namespace to sort" do
|
@@ -268,24 +347,24 @@ describe "redis" do
|
|
268
347
|
@namespaced.set('value_1', 'a')
|
269
348
|
@namespaced.set('value_2', 'b')
|
270
349
|
|
271
|
-
@namespaced.sort('foo').
|
272
|
-
@namespaced.sort('foo', :limit => [0, 1]).
|
273
|
-
@namespaced.sort('foo', :order => 'desc').
|
274
|
-
@namespaced.sort('foo', :by => 'weight_*').
|
275
|
-
@namespaced.sort('foo', :get => 'value_*').
|
276
|
-
@namespaced.sort('foo', :get => '#').
|
277
|
-
@namespaced.sort('foo', :get => ['#', 'value_*']).
|
350
|
+
expect(@namespaced.sort('foo')).to eq(%w( 1 2 ))
|
351
|
+
expect(@namespaced.sort('foo', :limit => [0, 1])).to eq(%w( 1 ))
|
352
|
+
expect(@namespaced.sort('foo', :order => 'desc')).to eq(%w( 2 1 ))
|
353
|
+
expect(@namespaced.sort('foo', :by => 'weight_*')).to eq(%w( 2 1 ))
|
354
|
+
expect(@namespaced.sort('foo', :get => 'value_*')).to eq(%w( a b ))
|
355
|
+
expect(@namespaced.sort('foo', :get => '#')).to eq(%w( 1 2 ))
|
356
|
+
expect(@namespaced.sort('foo', :get => ['#', 'value_*'])).to eq([["1", "a"], ["2", "b"]])
|
278
357
|
|
279
358
|
@namespaced.sort('foo', :store => 'result')
|
280
|
-
@namespaced.lrange('result', 0, -1).
|
359
|
+
expect(@namespaced.lrange('result', 0, -1)).to eq(%w( 1 2 ))
|
281
360
|
end
|
282
361
|
|
283
362
|
it "should yield the correct list of keys" do
|
284
363
|
@namespaced.set("foo", 1)
|
285
364
|
@namespaced.set("bar", 2)
|
286
365
|
@namespaced.set("baz", 3)
|
287
|
-
@namespaced.keys("*").sort.
|
288
|
-
@namespaced.keys.sort.
|
366
|
+
expect(@namespaced.keys("*").sort).to eq(%w( bar baz foo ))
|
367
|
+
expect(@namespaced.keys.sort).to eq(%w( bar baz foo ))
|
289
368
|
end
|
290
369
|
|
291
370
|
it "should add namepsace to multi blocks" do
|
@@ -294,7 +373,7 @@ describe "redis" do
|
|
294
373
|
r.del "foo"
|
295
374
|
r.mapped_hmset "foo", {"key1" => "value1"}
|
296
375
|
end
|
297
|
-
@namespaced.hgetall("foo").
|
376
|
+
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
298
377
|
end
|
299
378
|
|
300
379
|
it "should pass through multi commands without block" do
|
@@ -305,14 +384,14 @@ describe "redis" do
|
|
305
384
|
@namespaced.mapped_hmset "foo", {"key1" => "value1"}
|
306
385
|
@namespaced.exec
|
307
386
|
|
308
|
-
@namespaced.hgetall("foo").
|
387
|
+
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
309
388
|
end
|
310
389
|
|
311
390
|
it 'should return futures without attempting to remove namespaces' do
|
312
391
|
@namespaced.multi do
|
313
392
|
@future = @namespaced.keys('*')
|
314
393
|
end
|
315
|
-
@future.class.
|
394
|
+
expect(@future.class).to be(Redis::Future)
|
316
395
|
end
|
317
396
|
|
318
397
|
it "should add namespace to pipelined blocks" do
|
@@ -321,7 +400,7 @@ describe "redis" do
|
|
321
400
|
r.del "foo"
|
322
401
|
r.mapped_hmset "foo", {"key1" => "value1"}
|
323
402
|
end
|
324
|
-
@namespaced.hgetall("foo").
|
403
|
+
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
325
404
|
end
|
326
405
|
|
327
406
|
it "should returned response array from pipelined block" do
|
@@ -330,65 +409,125 @@ describe "redis" do
|
|
330
409
|
r.get("foo")
|
331
410
|
r.get("key")
|
332
411
|
end
|
333
|
-
result.
|
412
|
+
expect(result).to eq(["bar", "value"])
|
413
|
+
end
|
414
|
+
|
415
|
+
it "is thread safe for multi blocks" do
|
416
|
+
mon = Monitor.new
|
417
|
+
entered = false
|
418
|
+
entered_cond = mon.new_cond
|
419
|
+
|
420
|
+
thread = Thread.new do
|
421
|
+
mon.synchronize do
|
422
|
+
entered_cond.wait_until { entered }
|
423
|
+
@namespaced.multi
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
@namespaced.multi do |transaction|
|
428
|
+
entered = true
|
429
|
+
mon.synchronize { entered_cond.signal }
|
430
|
+
thread.join(0.1)
|
431
|
+
transaction.get("foo")
|
432
|
+
end
|
433
|
+
thread.join
|
334
434
|
end
|
335
435
|
|
336
436
|
it "should add namespace to strlen" do
|
337
437
|
@namespaced.set("mykey", "123456")
|
338
|
-
@namespaced.strlen("mykey").
|
438
|
+
expect(@namespaced.strlen("mykey")).to eq(6)
|
339
439
|
end
|
340
440
|
|
341
441
|
it "should not add namespace to echo" do
|
342
|
-
@namespaced.echo(123).
|
442
|
+
expect(@namespaced.echo(123)).to eq("123")
|
343
443
|
end
|
344
444
|
|
345
445
|
it 'should not add namespace to disconnect!' do
|
346
|
-
expect(@redis).to receive(:disconnect!).with().and_call_original
|
446
|
+
expect(@redis).to receive(:disconnect!).with(no_args).and_call_original
|
347
447
|
|
348
448
|
expect(@namespaced.disconnect!).to be nil
|
349
449
|
end
|
350
450
|
|
351
451
|
it "can change its namespace" do
|
352
|
-
@namespaced.get('foo').
|
452
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
353
453
|
@namespaced.set('foo', 'chris')
|
354
|
-
@namespaced.get('foo').
|
454
|
+
expect(@namespaced.get('foo')).to eq('chris')
|
355
455
|
|
356
|
-
@namespaced.namespace.
|
456
|
+
expect(@namespaced.namespace).to eq(:ns)
|
357
457
|
@namespaced.namespace = :spec
|
358
|
-
@namespaced.namespace.
|
458
|
+
expect(@namespaced.namespace).to eq(:spec)
|
359
459
|
|
360
|
-
@namespaced.get('foo').
|
460
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
361
461
|
@namespaced.set('foo', 'chris')
|
362
|
-
@namespaced.get('foo').
|
462
|
+
expect(@namespaced.get('foo')).to eq('chris')
|
363
463
|
end
|
364
464
|
|
365
465
|
it "can accept a temporary namespace" do
|
366
|
-
@namespaced.namespace.
|
367
|
-
@namespaced.get('foo').
|
466
|
+
expect(@namespaced.namespace).to eq(:ns)
|
467
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
368
468
|
|
369
469
|
@namespaced.namespace(:spec) do |temp_ns|
|
370
|
-
temp_ns.namespace.
|
371
|
-
temp_ns.get('foo').
|
470
|
+
expect(temp_ns.namespace).to eq(:spec)
|
471
|
+
expect(temp_ns.get('foo')).to eq(nil)
|
372
472
|
temp_ns.set('foo', 'jake')
|
373
|
-
temp_ns.get('foo').
|
473
|
+
expect(temp_ns.get('foo')).to eq('jake')
|
374
474
|
end
|
375
475
|
|
376
|
-
@namespaced.namespace.
|
377
|
-
@namespaced.get('foo').
|
476
|
+
expect(@namespaced.namespace).to eq(:ns)
|
477
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
378
478
|
end
|
379
479
|
|
380
480
|
it "should respond to :namespace=" do
|
381
|
-
@namespaced.respond_to?(:namespace=).
|
481
|
+
expect(@namespaced.respond_to?(:namespace=)).to eq(true)
|
382
482
|
end
|
383
483
|
|
384
484
|
it "should respond to :warning=" do
|
385
|
-
@namespaced.respond_to?(:warning=).
|
485
|
+
expect(@namespaced.respond_to?(:warning=)).to eq(true)
|
386
486
|
end
|
387
487
|
|
388
488
|
it "should raise an exception when an unknown command is passed" do
|
389
489
|
expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
|
390
490
|
end
|
391
491
|
|
492
|
+
describe '#inspect' do
|
493
|
+
let(:single_level_names) { %i[first] }
|
494
|
+
let(:double_level_names) { %i[first second] }
|
495
|
+
let(:triple_level_names) { %i[first second third] }
|
496
|
+
let(:namespace_builder) do
|
497
|
+
->(redis, *namespaces) { namespaces.reduce(redis) { |r, n| Redis::Namespace.new(n, redis: r) } }
|
498
|
+
end
|
499
|
+
let(:regexp_builder) do
|
500
|
+
->(*namespaces) { %r{/#{namespaces.join(':')}>\z} }
|
501
|
+
end
|
502
|
+
|
503
|
+
context 'when one namespace' do
|
504
|
+
let(:single_namespaced) { namespace_builder.call(@redis, *single_level_names) }
|
505
|
+
let(:regexp) { regexp_builder.call(*single_level_names) }
|
506
|
+
|
507
|
+
it 'should have correct ending of inspect string' do
|
508
|
+
expect(regexp =~ single_namespaced.inspect).not_to be(nil)
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
context 'when two namespaces' do
|
513
|
+
let(:double_namespaced) { namespace_builder.call(@redis, *double_level_names) }
|
514
|
+
let(:regexp) { regexp_builder.call(*double_level_names) }
|
515
|
+
|
516
|
+
it 'should have correct ending of inspect string' do
|
517
|
+
expect(regexp =~ double_namespaced.inspect).not_to be(nil)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
context 'when three namespaces' do
|
522
|
+
let(:triple_namespaced) { namespace_builder.call(@redis, *triple_level_names) }
|
523
|
+
let(:regexp) { regexp_builder.call(*triple_level_names) }
|
524
|
+
|
525
|
+
it 'should have correct ending of inspect string' do
|
526
|
+
expect(regexp =~ triple_namespaced.inspect).not_to be(nil)
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
392
531
|
# Redis 2.6 RC reports its version as 2.5.
|
393
532
|
if @redis_version >= Gem::Version.new("2.5.0")
|
394
533
|
describe "redis 2.6 commands" do
|
@@ -422,7 +561,7 @@ describe "redis" do
|
|
422
561
|
v = @namespaced.dump("foo")
|
423
562
|
@redis.del("ns:foo")
|
424
563
|
|
425
|
-
expect(@namespaced.restore("foo", 1000, v)).to
|
564
|
+
expect(@namespaced.restore("foo", 1000, v)).to be_truthy
|
426
565
|
expect(@redis.get("ns:foo")).to eq 'a'
|
427
566
|
expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
|
428
567
|
|
@@ -430,72 +569,72 @@ describe "redis" do
|
|
430
569
|
w = @namespaced.dump("bar")
|
431
570
|
@redis.del("ns:bar")
|
432
571
|
|
433
|
-
expect(@namespaced.restore("bar", 1000, w)).to
|
572
|
+
expect(@namespaced.restore("bar", 1000, w)).to be_truthy
|
434
573
|
expect(@redis.lrange('ns:bar', 0, -1)).to eq %w(b c d)
|
435
574
|
expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
|
436
575
|
end
|
437
576
|
|
438
577
|
it "should namespace hincrbyfloat" do
|
439
578
|
@namespaced.hset('mykey', 'field', 10.50)
|
440
|
-
@namespaced.hincrbyfloat('mykey', 'field', 0.1).
|
579
|
+
expect(@namespaced.hincrbyfloat('mykey', 'field', 0.1)).to eq(10.6)
|
441
580
|
end
|
442
581
|
|
443
582
|
it "should namespace incrbyfloat" do
|
444
583
|
@namespaced.set('mykey', 10.50)
|
445
|
-
@namespaced.incrbyfloat('mykey', 0.1).
|
584
|
+
expect(@namespaced.incrbyfloat('mykey', 0.1)).to eq(10.6)
|
446
585
|
end
|
447
586
|
|
448
587
|
it "should namespace object" do
|
449
588
|
@namespaced.set('foo', 1000)
|
450
|
-
@namespaced.object('encoding', 'foo').
|
589
|
+
expect(@namespaced.object('encoding', 'foo')).to eq('int')
|
451
590
|
end
|
452
591
|
|
453
592
|
it "should namespace persist" do
|
454
593
|
@namespaced.set('mykey', 'Hello')
|
455
594
|
@namespaced.expire('mykey', 60)
|
456
|
-
@namespaced.persist('mykey').
|
457
|
-
@namespaced.ttl('mykey').
|
595
|
+
expect(@namespaced.persist('mykey')).to eq(true)
|
596
|
+
expect(@namespaced.ttl('mykey')).to eq(-1)
|
458
597
|
end
|
459
598
|
|
460
599
|
it "should namespace pexpire" do
|
461
600
|
@namespaced.set('mykey', 'Hello')
|
462
|
-
@namespaced.pexpire('mykey', 60000).
|
601
|
+
expect(@namespaced.pexpire('mykey', 60000)).to eq(true)
|
463
602
|
end
|
464
603
|
|
465
604
|
it "should namespace pexpireat" do
|
466
605
|
@namespaced.set('mykey', 'Hello')
|
467
|
-
@namespaced.pexpire('mykey', 1555555555005).
|
606
|
+
expect(@namespaced.pexpire('mykey', 1555555555005)).to eq(true)
|
468
607
|
end
|
469
608
|
|
470
609
|
it "should namespace psetex" do
|
471
|
-
@namespaced.psetex('mykey', 10000, 'Hello').
|
472
|
-
@namespaced.get('mykey').
|
610
|
+
expect(@namespaced.psetex('mykey', 10000, 'Hello')).to eq('OK')
|
611
|
+
expect(@namespaced.get('mykey')).to eq('Hello')
|
473
612
|
end
|
474
613
|
|
475
614
|
it "should namespace pttl" do
|
476
615
|
@namespaced.set('mykey', 'Hello')
|
477
616
|
@namespaced.expire('mykey', 1)
|
478
|
-
@namespaced.pttl('mykey').
|
617
|
+
expect(@namespaced.pttl('mykey')).to be >= 0
|
479
618
|
end
|
480
619
|
|
481
620
|
it "should namespace eval keys passed in as array args" do
|
482
|
-
@namespaced.
|
483
|
-
eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2]).
|
484
|
-
|
621
|
+
expect(@namespaced.
|
622
|
+
eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2])).
|
623
|
+
to eq(%w[ns:k1 ns:k2])
|
485
624
|
end
|
486
625
|
|
487
626
|
it "should namespace eval keys passed in as hash args" do
|
488
|
-
@namespaced.
|
489
|
-
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
490
|
-
|
627
|
+
expect(@namespaced.
|
628
|
+
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
|
629
|
+
to eq(%w[ns:k1 ns:k2])
|
491
630
|
end
|
492
631
|
|
493
632
|
it "should namespace eval keys passed in as hash args unmodified" do
|
494
633
|
args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
|
495
634
|
args.freeze
|
496
|
-
@namespaced.
|
497
|
-
eval("return {KEYS[1], KEYS[2]}", args).
|
498
|
-
|
635
|
+
expect(@namespaced.
|
636
|
+
eval("return {KEYS[1], KEYS[2]}", args)).
|
637
|
+
to eq(%w[ns:k1 ns:k2])
|
499
638
|
end
|
500
639
|
|
501
640
|
context '#evalsha' do
|
@@ -504,23 +643,23 @@ describe "redis" do
|
|
504
643
|
end
|
505
644
|
|
506
645
|
it "should namespace evalsha keys passed in as array args" do
|
507
|
-
@namespaced.
|
508
|
-
evalsha(sha, %w[k1 k2], %w[arg1 arg2]).
|
509
|
-
|
646
|
+
expect(@namespaced.
|
647
|
+
evalsha(sha, %w[k1 k2], %w[arg1 arg2])).
|
648
|
+
to eq(%w[ns:k1 ns:k2])
|
510
649
|
end
|
511
650
|
|
512
651
|
it "should namespace evalsha keys passed in as hash args" do
|
513
|
-
@namespaced.
|
514
|
-
evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
515
|
-
|
652
|
+
expect(@namespaced.
|
653
|
+
evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
|
654
|
+
to eq(%w[ns:k1 ns:k2])
|
516
655
|
end
|
517
656
|
|
518
657
|
it "should namespace evalsha keys passed in as hash args unmodified" do
|
519
658
|
args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
|
520
659
|
args.freeze
|
521
|
-
@namespaced.
|
522
|
-
evalsha(sha, args).
|
523
|
-
|
660
|
+
expect(@namespaced.
|
661
|
+
evalsha(sha, args)).
|
662
|
+
to eq(%w[ns:k1 ns:k2])
|
524
663
|
end
|
525
664
|
end
|
526
665
|
|
@@ -529,13 +668,13 @@ describe "redis" do
|
|
529
668
|
let(:sha) { @redis.script(:load, "return {KEYS[1], KEYS[2]}") }
|
530
669
|
|
531
670
|
it "should namespace eval keys passed in as hash args" do
|
532
|
-
nested_namespace.
|
533
|
-
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
534
|
-
|
671
|
+
expect(nested_namespace.
|
672
|
+
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
|
673
|
+
to eq(%w[ns:nest:k1 ns:nest:k2])
|
535
674
|
end
|
536
675
|
it "should namespace evalsha keys passed in as hash args" do
|
537
|
-
nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
538
|
-
|
676
|
+
expect(nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
|
677
|
+
to eq(%w[ns:nest:k1 ns:nest:k2])
|
539
678
|
end
|
540
679
|
end
|
541
680
|
end
|
@@ -564,16 +703,16 @@ describe "redis" do
|
|
564
703
|
context 'when :match supplied' do
|
565
704
|
it 'should retrieve the proper keys' do
|
566
705
|
_, result = @namespaced.scan(0, :match => 'zeta:*', :count => 1000)
|
567
|
-
result.
|
706
|
+
expect(result).to match_array(matching_namespaced_keys)
|
568
707
|
end
|
569
708
|
end
|
570
709
|
context 'without :match supplied' do
|
571
710
|
it 'should retrieve the proper keys' do
|
572
711
|
_, result = @namespaced.scan(0, :count => 1000)
|
573
|
-
result.
|
712
|
+
expect(result).to match_array(namespaced_keys)
|
574
713
|
end
|
575
714
|
end
|
576
|
-
end if Redis.
|
715
|
+
end if Redis.new.respond_to?(:scan)
|
577
716
|
|
578
717
|
context '#scan_each' do
|
579
718
|
context 'when :match supplied' do
|
@@ -581,13 +720,13 @@ describe "redis" do
|
|
581
720
|
it 'should yield unnamespaced' do
|
582
721
|
results = []
|
583
722
|
@namespaced.scan_each(:match => 'zeta:*', :count => 1000) {|k| results << k }
|
584
|
-
results.
|
723
|
+
expect(results).to match_array(matching_namespaced_keys)
|
585
724
|
end
|
586
725
|
end
|
587
726
|
context 'without a block' do
|
588
727
|
it 'should return an Enumerator that un-namespaces' do
|
589
728
|
enum = @namespaced.scan_each(:match => 'zeta:*', :count => 1000)
|
590
|
-
enum.to_a.
|
729
|
+
expect(enum.to_a).to match_array(matching_namespaced_keys)
|
591
730
|
end
|
592
731
|
end
|
593
732
|
end
|
@@ -596,17 +735,17 @@ describe "redis" do
|
|
596
735
|
it 'should yield unnamespaced' do
|
597
736
|
results = []
|
598
737
|
@namespaced.scan_each(:count => 1000){ |k| results << k }
|
599
|
-
results.
|
738
|
+
expect(results).to match_array(namespaced_keys)
|
600
739
|
end
|
601
740
|
end
|
602
741
|
context 'without a block' do
|
603
742
|
it 'should return an Enumerator that un-namespaces' do
|
604
743
|
enum = @namespaced.scan_each(:count => 1000)
|
605
|
-
enum.to_a.
|
744
|
+
expect(enum.to_a).to match_array(namespaced_keys)
|
606
745
|
end
|
607
746
|
end
|
608
747
|
end
|
609
|
-
end if Redis.
|
748
|
+
end if Redis.new.respond_to?(:scan_each)
|
610
749
|
end
|
611
750
|
|
612
751
|
context 'hash scan methods' do
|
@@ -625,16 +764,16 @@ describe "redis" do
|
|
625
764
|
context 'when supplied :match' do
|
626
765
|
it 'should retrieve the proper keys' do
|
627
766
|
_, results = @namespaced.hscan('hsh', 0, :match => 'zeta:*')
|
628
|
-
results.
|
767
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
629
768
|
end
|
630
769
|
end
|
631
770
|
context 'without :match supplied' do
|
632
771
|
it 'should retrieve all hash keys' do
|
633
772
|
_, results = @namespaced.hscan('hsh', 0)
|
634
|
-
results.
|
773
|
+
expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
|
635
774
|
end
|
636
775
|
end
|
637
|
-
end if Redis.
|
776
|
+
end if Redis.new.respond_to?(:hscan)
|
638
777
|
|
639
778
|
context '#hscan_each' do
|
640
779
|
context 'when :match supplied' do
|
@@ -642,13 +781,13 @@ describe "redis" do
|
|
642
781
|
it 'should yield the correct hash keys unchanged' do
|
643
782
|
results = []
|
644
783
|
@namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
|
645
|
-
results.
|
784
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
646
785
|
end
|
647
786
|
end
|
648
787
|
context 'without a block' do
|
649
788
|
it 'should return an Enumerator that yields the correct hash keys unchanged' do
|
650
789
|
enum = @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000)
|
651
|
-
enum.to_a.
|
790
|
+
expect(enum.to_a).to match_array(hash_matching_subset.to_a)
|
652
791
|
end
|
653
792
|
end
|
654
793
|
end
|
@@ -657,17 +796,17 @@ describe "redis" do
|
|
657
796
|
it 'should yield all hash keys unchanged' do
|
658
797
|
results = []
|
659
798
|
@namespaced.hscan_each('hsh', :count => 1000){ |k| results << k }
|
660
|
-
results.
|
799
|
+
expect(results).to match_array(hash.to_a)
|
661
800
|
end
|
662
801
|
end
|
663
802
|
context 'without a block' do
|
664
803
|
it 'should return an Enumerator that yields all keys unchanged' do
|
665
804
|
enum = @namespaced.hscan_each('hsh', :count => 1000)
|
666
|
-
enum.to_a.
|
805
|
+
expect(enum.to_a).to match_array(hash.to_a)
|
667
806
|
end
|
668
807
|
end
|
669
808
|
end
|
670
|
-
end if Redis.
|
809
|
+
end if Redis.new.respond_to?(:hscan_each)
|
671
810
|
end
|
672
811
|
|
673
812
|
context 'set scan methods' do
|
@@ -686,16 +825,16 @@ describe "redis" do
|
|
686
825
|
context 'when supplied :match' do
|
687
826
|
it 'should retrieve the matching set members from the proper set' do
|
688
827
|
_, results = @namespaced.sscan('set', 0, :match => 'zeta:*', :count => 1000)
|
689
|
-
results.
|
828
|
+
expect(results).to match_array(matching_subset)
|
690
829
|
end
|
691
830
|
end
|
692
831
|
context 'without :match supplied' do
|
693
832
|
it 'should retrieve all set members from the proper set' do
|
694
833
|
_, results = @namespaced.sscan('set', 0, :count => 1000)
|
695
|
-
results.
|
834
|
+
expect(results).to match_array(set)
|
696
835
|
end
|
697
836
|
end
|
698
|
-
end if Redis.
|
837
|
+
end if Redis.new.respond_to?(:sscan)
|
699
838
|
|
700
839
|
context '#sscan_each' do
|
701
840
|
context 'when :match supplied' do
|
@@ -703,13 +842,13 @@ describe "redis" do
|
|
703
842
|
it 'should yield the correct hset elements unchanged' do
|
704
843
|
results = []
|
705
844
|
@namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
|
706
|
-
results.
|
845
|
+
expect(results).to match_array(matching_subset)
|
707
846
|
end
|
708
847
|
end
|
709
848
|
context 'without a block' do
|
710
849
|
it 'should return an Enumerator that yields the correct set elements unchanged' do
|
711
850
|
enum = @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000)
|
712
|
-
enum.to_a.
|
851
|
+
expect(enum.to_a).to match_array(matching_subset)
|
713
852
|
end
|
714
853
|
end
|
715
854
|
end
|
@@ -718,17 +857,17 @@ describe "redis" do
|
|
718
857
|
it 'should yield all set elements unchanged' do
|
719
858
|
results = []
|
720
859
|
@namespaced.sscan_each('set', :count => 1000){ |k| results << k }
|
721
|
-
results.
|
860
|
+
expect(results).to match_array(set)
|
722
861
|
end
|
723
862
|
end
|
724
863
|
context 'without a block' do
|
725
864
|
it 'should return an Enumerator that yields all set elements unchanged' do
|
726
865
|
enum = @namespaced.sscan_each('set', :count => 1000)
|
727
|
-
enum.to_a.
|
866
|
+
expect(enum.to_a).to match_array(set)
|
728
867
|
end
|
729
868
|
end
|
730
869
|
end
|
731
|
-
end if Redis.
|
870
|
+
end if Redis.new.respond_to?(:sscan_each)
|
732
871
|
end
|
733
872
|
|
734
873
|
context 'zset scan methods' do
|
@@ -748,17 +887,17 @@ describe "redis" do
|
|
748
887
|
it 'should retrieve the matching set elements and their scores' do
|
749
888
|
results = []
|
750
889
|
@namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms }
|
751
|
-
results.
|
890
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
752
891
|
end
|
753
892
|
end
|
754
893
|
context 'without :match supplied' do
|
755
894
|
it 'should retrieve all set elements and their scores' do
|
756
895
|
results = []
|
757
896
|
@namespaced.zscan_each('zset', :count => 1000) { |ms| results << ms }
|
758
|
-
results.
|
897
|
+
expect(results).to match_array(hash.to_a)
|
759
898
|
end
|
760
899
|
end
|
761
|
-
end if Redis.
|
900
|
+
end if Redis.new.respond_to?(:zscan)
|
762
901
|
|
763
902
|
context '#zscan_each' do
|
764
903
|
context 'when :match supplied' do
|
@@ -766,13 +905,13 @@ describe "redis" do
|
|
766
905
|
it 'should yield the correct set elements and scores unchanged' do
|
767
906
|
results = []
|
768
907
|
@namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms}
|
769
|
-
results.
|
908
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
770
909
|
end
|
771
910
|
end
|
772
911
|
context 'without a block' do
|
773
912
|
it 'should return an Enumerator that yields the correct set elements and scoresunchanged' do
|
774
913
|
enum = @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000)
|
775
|
-
enum.to_a.
|
914
|
+
expect(enum.to_a).to match_array(hash_matching_subset.to_a)
|
776
915
|
end
|
777
916
|
end
|
778
917
|
end
|
@@ -781,17 +920,17 @@ describe "redis" do
|
|
781
920
|
it 'should yield all set elements and scores unchanged' do
|
782
921
|
results = []
|
783
922
|
@namespaced.zscan_each('zset', :count => 1000){ |ms| results << ms }
|
784
|
-
results.
|
923
|
+
expect(results).to match_array(hash.to_a)
|
785
924
|
end
|
786
925
|
end
|
787
926
|
context 'without a block' do
|
788
927
|
it 'should return an Enumerator that yields all set elements and scores unchanged' do
|
789
928
|
enum = @namespaced.zscan_each('zset', :count => 1000)
|
790
|
-
enum.to_a.
|
929
|
+
expect(enum.to_a).to match_array(hash.to_a)
|
791
930
|
end
|
792
931
|
end
|
793
932
|
end
|
794
|
-
end if Redis.
|
933
|
+
end if Redis.new.respond_to?(:zscan_each)
|
795
934
|
end
|
796
935
|
end
|
797
936
|
end
|
@@ -799,12 +938,12 @@ describe "redis" do
|
|
799
938
|
if @redis_version >= Gem::Version.new("2.8.9")
|
800
939
|
it 'should namespace pfadd' do
|
801
940
|
5.times { |n| @namespaced.pfadd("pf", n) }
|
802
|
-
@redis.pfcount("ns:pf").
|
941
|
+
expect(@redis.pfcount("ns:pf")).to eq(5)
|
803
942
|
end
|
804
943
|
|
805
944
|
it 'should namespace pfcount' do
|
806
945
|
5.times { |n| @redis.pfadd("ns:pf", n) }
|
807
|
-
@namespaced.pfcount("pf").
|
946
|
+
expect(@namespaced.pfcount("pf")).to eq(5)
|
808
947
|
end
|
809
948
|
|
810
949
|
it 'should namespace pfmerge' do
|
@@ -814,7 +953,18 @@ describe "redis" do
|
|
814
953
|
end
|
815
954
|
|
816
955
|
@namespaced.pfmerge("pfc", "pfa", "pfb")
|
817
|
-
@redis.pfcount("ns:pfc").
|
956
|
+
expect(@redis.pfcount("ns:pfc")).to eq(10)
|
957
|
+
end
|
958
|
+
end
|
959
|
+
|
960
|
+
describe :full_namespace do
|
961
|
+
it "should return the full namespace including sub namespaces" do
|
962
|
+
sub_namespaced = Redis::Namespace.new(:sub1, :redis => @namespaced)
|
963
|
+
sub_sub_namespaced = Redis::Namespace.new(:sub2, :redis => sub_namespaced)
|
964
|
+
|
965
|
+
expect(@namespaced.full_namespace).to eql("ns")
|
966
|
+
expect(sub_namespaced.full_namespace).to eql("ns:sub1")
|
967
|
+
expect(sub_sub_namespaced.full_namespace).to eql("ns:sub1:sub2")
|
818
968
|
end
|
819
969
|
end
|
820
970
|
end
|