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