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