redis-namespace 1.5.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/LICENSE +17 -16
- data/README.md +85 -20
- data/lib/redis/namespace.rb +155 -44
- data/lib/redis/namespace/version.rb +1 -1
- data/spec/deprecation_spec.rb +34 -2
- data/spec/redis_spec.rb +321 -179
- data/spec/spec_helper.rb +5 -0
- metadata +38 -31
data/spec/deprecation_spec.rb
CHANGED
@@ -34,6 +34,7 @@ describe Redis::Namespace do
|
|
34
34
|
allow(redis).to receive(:unhandled) do |*args|
|
35
35
|
"unhandled(#{args.inspect})"
|
36
36
|
end
|
37
|
+
allow(redis).to receive(:flushdb).and_return("OK")
|
37
38
|
end
|
38
39
|
|
39
40
|
# This behaviour will hold true after the 2.x migration
|
@@ -42,7 +43,7 @@ describe Redis::Namespace do
|
|
42
43
|
its(:deprecations?) { should be true }
|
43
44
|
|
44
45
|
context('with an unhandled command') do
|
45
|
-
it {
|
46
|
+
it { is_expected.not_to respond_to :unhandled }
|
46
47
|
|
47
48
|
it('raises a NoMethodError') do
|
48
49
|
expect do
|
@@ -50,6 +51,16 @@ describe Redis::Namespace do
|
|
50
51
|
end.to raise_exception NoMethodError
|
51
52
|
end
|
52
53
|
end
|
54
|
+
|
55
|
+
context('with an administrative command') do
|
56
|
+
it { is_expected.not_to respond_to :flushdb }
|
57
|
+
|
58
|
+
it('raises a NoMethodError') do
|
59
|
+
expect do
|
60
|
+
namespaced.flushdb
|
61
|
+
end.to raise_exception NoMethodError
|
62
|
+
end
|
63
|
+
end
|
53
64
|
end
|
54
65
|
|
55
66
|
# This behaviour will no longer be available after the 2.x migration
|
@@ -58,7 +69,7 @@ describe Redis::Namespace do
|
|
58
69
|
its(:deprecations?) { should be false }
|
59
70
|
|
60
71
|
context('with an an unhandled command') do
|
61
|
-
it {
|
72
|
+
it { is_expected.to respond_to :unhandled }
|
62
73
|
|
63
74
|
it 'blindly passes through' do
|
64
75
|
expect(redis).to receive(:unhandled)
|
@@ -77,6 +88,7 @@ describe Redis::Namespace do
|
|
77
88
|
|
78
89
|
expect(warning).to_not be_empty
|
79
90
|
expect(warning).to include %q(Passing 'unhandled' command to redis as is)
|
91
|
+
expect(warning).to include %q(blind passthrough)
|
80
92
|
expect(warning).to include __FILE__
|
81
93
|
end
|
82
94
|
|
@@ -87,10 +99,30 @@ describe Redis::Namespace do
|
|
87
99
|
namespaced.unhandled('bar')
|
88
100
|
end
|
89
101
|
warning = stderr.tap(&:rewind).read
|
102
|
+
|
90
103
|
expect(warning).to be_empty
|
91
104
|
end
|
92
105
|
end
|
93
106
|
end
|
107
|
+
|
108
|
+
context('with an administrative command') do
|
109
|
+
it { is_expected.to respond_to :flushdb }
|
110
|
+
it 'processes the command' do
|
111
|
+
expect(redis).to receive(:flushdb)
|
112
|
+
capture_stderr { namespaced.flushdb }
|
113
|
+
end
|
114
|
+
it 'warns with helpful output' do
|
115
|
+
capture_stderr(stderr = StringIO.new) do
|
116
|
+
namespaced.flushdb
|
117
|
+
end
|
118
|
+
warning = stderr.tap(&:rewind).read
|
119
|
+
|
120
|
+
expect(warning).to_not be_empty
|
121
|
+
expect(warning).to include %q(Passing 'flushdb' command to redis as is)
|
122
|
+
expect(warning).to include %q(administrative)
|
123
|
+
expect(warning).to include __FILE__
|
124
|
+
end
|
125
|
+
end
|
94
126
|
end
|
95
127
|
end
|
96
128
|
end
|
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
|
@@ -12,8 +13,8 @@ describe "redis" do
|
|
12
13
|
|
13
14
|
before(:each) do
|
14
15
|
@namespaced = Redis::Namespace.new(:ns, :redis => @redis)
|
15
|
-
@
|
16
|
-
@redis
|
16
|
+
@redis.flushdb
|
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,68 +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")
|
408
|
+
end
|
409
|
+
|
410
|
+
it 'should not add namespace to disconnect!' do
|
411
|
+
expect(@redis).to receive(:disconnect!).with(no_args).and_call_original
|
412
|
+
|
413
|
+
expect(@namespaced.disconnect!).to be nil
|
338
414
|
end
|
339
415
|
|
340
416
|
it "can change its namespace" do
|
341
|
-
@namespaced
|
342
|
-
@namespaced
|
343
|
-
@namespaced
|
417
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
418
|
+
@namespaced.set('foo', 'chris')
|
419
|
+
expect(@namespaced.get('foo')).to eq('chris')
|
344
420
|
|
345
|
-
@namespaced.namespace.
|
421
|
+
expect(@namespaced.namespace).to eq(:ns)
|
346
422
|
@namespaced.namespace = :spec
|
347
|
-
@namespaced.namespace.
|
423
|
+
expect(@namespaced.namespace).to eq(:spec)
|
348
424
|
|
349
|
-
@namespaced
|
350
|
-
@namespaced
|
351
|
-
@namespaced
|
425
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
426
|
+
@namespaced.set('foo', 'chris')
|
427
|
+
expect(@namespaced.get('foo')).to eq('chris')
|
352
428
|
end
|
353
429
|
|
354
430
|
it "can accept a temporary namespace" do
|
355
|
-
@namespaced.namespace.
|
356
|
-
@namespaced
|
431
|
+
expect(@namespaced.namespace).to eq(:ns)
|
432
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
357
433
|
|
358
434
|
@namespaced.namespace(:spec) do |temp_ns|
|
359
|
-
temp_ns.namespace.
|
360
|
-
temp_ns
|
361
|
-
temp_ns
|
362
|
-
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')
|
363
439
|
end
|
364
440
|
|
365
|
-
@namespaced.namespace.
|
366
|
-
@namespaced
|
441
|
+
expect(@namespaced.namespace).to eq(:ns)
|
442
|
+
expect(@namespaced.get('foo')).to eq(nil)
|
367
443
|
end
|
368
444
|
|
369
445
|
it "should respond to :namespace=" do
|
370
|
-
@namespaced.respond_to?(:namespace=).
|
446
|
+
expect(@namespaced.respond_to?(:namespace=)).to eq(true)
|
371
447
|
end
|
372
448
|
|
373
449
|
it "should respond to :warning=" do
|
374
|
-
@namespaced.respond_to?(:warning=).
|
450
|
+
expect(@namespaced.respond_to?(:warning=)).to eq(true)
|
375
451
|
end
|
376
452
|
|
377
453
|
it "should raise an exception when an unknown command is passed" do
|
378
454
|
expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
|
379
455
|
end
|
380
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
|
+
|
381
496
|
# Redis 2.6 RC reports its version as 2.5.
|
382
497
|
if @redis_version >= Gem::Version.new("2.5.0")
|
383
498
|
describe "redis 2.6 commands" do
|
@@ -411,7 +526,7 @@ describe "redis" do
|
|
411
526
|
v = @namespaced.dump("foo")
|
412
527
|
@redis.del("ns:foo")
|
413
528
|
|
414
|
-
expect(@namespaced.restore("foo", 1000, v)).to
|
529
|
+
expect(@namespaced.restore("foo", 1000, v)).to be_truthy
|
415
530
|
expect(@redis.get("ns:foo")).to eq 'a'
|
416
531
|
expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
|
417
532
|
|
@@ -419,96 +534,112 @@ describe "redis" do
|
|
419
534
|
w = @namespaced.dump("bar")
|
420
535
|
@redis.del("ns:bar")
|
421
536
|
|
422
|
-
expect(@namespaced.restore("bar", 1000, w)).to
|
537
|
+
expect(@namespaced.restore("bar", 1000, w)).to be_truthy
|
423
538
|
expect(@redis.lrange('ns:bar', 0, -1)).to eq %w(b c d)
|
424
539
|
expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
|
425
540
|
end
|
426
541
|
|
427
542
|
it "should namespace hincrbyfloat" do
|
428
543
|
@namespaced.hset('mykey', 'field', 10.50)
|
429
|
-
@namespaced.hincrbyfloat('mykey', 'field', 0.1).
|
544
|
+
expect(@namespaced.hincrbyfloat('mykey', 'field', 0.1)).to eq(10.6)
|
430
545
|
end
|
431
546
|
|
432
547
|
it "should namespace incrbyfloat" do
|
433
548
|
@namespaced.set('mykey', 10.50)
|
434
|
-
@namespaced.incrbyfloat('mykey', 0.1).
|
549
|
+
expect(@namespaced.incrbyfloat('mykey', 0.1)).to eq(10.6)
|
435
550
|
end
|
436
551
|
|
437
552
|
it "should namespace object" do
|
438
553
|
@namespaced.set('foo', 1000)
|
439
|
-
@namespaced.object('encoding', 'foo').
|
554
|
+
expect(@namespaced.object('encoding', 'foo')).to eq('int')
|
440
555
|
end
|
441
556
|
|
442
557
|
it "should namespace persist" do
|
443
558
|
@namespaced.set('mykey', 'Hello')
|
444
559
|
@namespaced.expire('mykey', 60)
|
445
|
-
@namespaced.persist('mykey').
|
446
|
-
@namespaced.ttl('mykey').
|
560
|
+
expect(@namespaced.persist('mykey')).to eq(true)
|
561
|
+
expect(@namespaced.ttl('mykey')).to eq(-1)
|
447
562
|
end
|
448
563
|
|
449
564
|
it "should namespace pexpire" do
|
450
565
|
@namespaced.set('mykey', 'Hello')
|
451
|
-
@namespaced.pexpire('mykey', 60000).
|
566
|
+
expect(@namespaced.pexpire('mykey', 60000)).to eq(true)
|
452
567
|
end
|
453
568
|
|
454
569
|
it "should namespace pexpireat" do
|
455
570
|
@namespaced.set('mykey', 'Hello')
|
456
|
-
@namespaced.pexpire('mykey', 1555555555005).
|
571
|
+
expect(@namespaced.pexpire('mykey', 1555555555005)).to eq(true)
|
457
572
|
end
|
458
573
|
|
459
574
|
it "should namespace psetex" do
|
460
|
-
@namespaced.psetex('mykey', 10000, 'Hello').
|
461
|
-
@namespaced.get('mykey').
|
575
|
+
expect(@namespaced.psetex('mykey', 10000, 'Hello')).to eq('OK')
|
576
|
+
expect(@namespaced.get('mykey')).to eq('Hello')
|
462
577
|
end
|
463
578
|
|
464
579
|
it "should namespace pttl" do
|
465
580
|
@namespaced.set('mykey', 'Hello')
|
466
581
|
@namespaced.expire('mykey', 1)
|
467
|
-
@namespaced.pttl('mykey').
|
582
|
+
expect(@namespaced.pttl('mykey')).to be >= 0
|
468
583
|
end
|
469
584
|
|
470
585
|
it "should namespace eval keys passed in as array args" do
|
471
|
-
@namespaced.
|
472
|
-
eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2]).
|
473
|
-
|
586
|
+
expect(@namespaced.
|
587
|
+
eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2])).
|
588
|
+
to eq(%w[ns:k1 ns:k2])
|
474
589
|
end
|
475
590
|
|
476
591
|
it "should namespace eval keys passed in as hash args" do
|
477
|
-
@namespaced.
|
478
|
-
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
479
|
-
|
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])
|
595
|
+
end
|
596
|
+
|
597
|
+
it "should namespace eval keys passed in as hash args unmodified" do
|
598
|
+
args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
|
599
|
+
args.freeze
|
600
|
+
expect(@namespaced.
|
601
|
+
eval("return {KEYS[1], KEYS[2]}", args)).
|
602
|
+
to eq(%w[ns:k1 ns:k2])
|
480
603
|
end
|
481
604
|
|
482
605
|
context '#evalsha' do
|
483
606
|
let!(:sha) do
|
484
|
-
@
|
607
|
+
@redis.script(:load, "return {KEYS[1], KEYS[2]}")
|
485
608
|
end
|
486
609
|
|
487
610
|
it "should namespace evalsha keys passed in as array args" do
|
488
|
-
@namespaced.
|
489
|
-
evalsha(sha, %w[k1 k2], %w[arg1 arg2]).
|
490
|
-
|
611
|
+
expect(@namespaced.
|
612
|
+
evalsha(sha, %w[k1 k2], %w[arg1 arg2])).
|
613
|
+
to eq(%w[ns:k1 ns:k2])
|
491
614
|
end
|
492
615
|
|
493
616
|
it "should namespace evalsha keys passed in as hash args" do
|
494
|
-
@namespaced.
|
495
|
-
evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
496
|
-
|
617
|
+
expect(@namespaced.
|
618
|
+
evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
|
619
|
+
to eq(%w[ns:k1 ns:k2])
|
620
|
+
end
|
621
|
+
|
622
|
+
it "should namespace evalsha keys passed in as hash args unmodified" do
|
623
|
+
args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
|
624
|
+
args.freeze
|
625
|
+
expect(@namespaced.
|
626
|
+
evalsha(sha, args)).
|
627
|
+
to eq(%w[ns:k1 ns:k2])
|
497
628
|
end
|
498
629
|
end
|
499
630
|
|
500
631
|
context "in a nested namespace" do
|
501
632
|
let(:nested_namespace) { Redis::Namespace.new(:nest, :redis => @namespaced) }
|
502
|
-
let(:sha) {
|
633
|
+
let(:sha) { @redis.script(:load, "return {KEYS[1], KEYS[2]}") }
|
503
634
|
|
504
635
|
it "should namespace eval keys passed in as hash args" do
|
505
|
-
nested_namespace.
|
506
|
-
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
507
|
-
|
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])
|
508
639
|
end
|
509
640
|
it "should namespace evalsha keys passed in as hash args" do
|
510
|
-
nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
511
|
-
|
641
|
+
expect(nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
|
642
|
+
to eq(%w[ns:nest:k1 ns:nest:k2])
|
512
643
|
end
|
513
644
|
end
|
514
645
|
end
|
@@ -537,13 +668,13 @@ describe "redis" do
|
|
537
668
|
context 'when :match supplied' do
|
538
669
|
it 'should retrieve the proper keys' do
|
539
670
|
_, result = @namespaced.scan(0, :match => 'zeta:*', :count => 1000)
|
540
|
-
result.
|
671
|
+
expect(result).to match_array(matching_namespaced_keys)
|
541
672
|
end
|
542
673
|
end
|
543
674
|
context 'without :match supplied' do
|
544
675
|
it 'should retrieve the proper keys' do
|
545
676
|
_, result = @namespaced.scan(0, :count => 1000)
|
546
|
-
result.
|
677
|
+
expect(result).to match_array(namespaced_keys)
|
547
678
|
end
|
548
679
|
end
|
549
680
|
end if Redis.current.respond_to?(:scan)
|
@@ -554,13 +685,13 @@ describe "redis" do
|
|
554
685
|
it 'should yield unnamespaced' do
|
555
686
|
results = []
|
556
687
|
@namespaced.scan_each(:match => 'zeta:*', :count => 1000) {|k| results << k }
|
557
|
-
results.
|
688
|
+
expect(results).to match_array(matching_namespaced_keys)
|
558
689
|
end
|
559
690
|
end
|
560
691
|
context 'without a block' do
|
561
692
|
it 'should return an Enumerator that un-namespaces' do
|
562
693
|
enum = @namespaced.scan_each(:match => 'zeta:*', :count => 1000)
|
563
|
-
enum.to_a.
|
694
|
+
expect(enum.to_a).to match_array(matching_namespaced_keys)
|
564
695
|
end
|
565
696
|
end
|
566
697
|
end
|
@@ -569,13 +700,13 @@ describe "redis" do
|
|
569
700
|
it 'should yield unnamespaced' do
|
570
701
|
results = []
|
571
702
|
@namespaced.scan_each(:count => 1000){ |k| results << k }
|
572
|
-
results.
|
703
|
+
expect(results).to match_array(namespaced_keys)
|
573
704
|
end
|
574
705
|
end
|
575
706
|
context 'without a block' do
|
576
707
|
it 'should return an Enumerator that un-namespaces' do
|
577
708
|
enum = @namespaced.scan_each(:count => 1000)
|
578
|
-
enum.to_a.
|
709
|
+
expect(enum.to_a).to match_array(namespaced_keys)
|
579
710
|
end
|
580
711
|
end
|
581
712
|
end
|
@@ -598,13 +729,13 @@ describe "redis" do
|
|
598
729
|
context 'when supplied :match' do
|
599
730
|
it 'should retrieve the proper keys' do
|
600
731
|
_, results = @namespaced.hscan('hsh', 0, :match => 'zeta:*')
|
601
|
-
results.
|
732
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
602
733
|
end
|
603
734
|
end
|
604
735
|
context 'without :match supplied' do
|
605
736
|
it 'should retrieve all hash keys' do
|
606
737
|
_, results = @namespaced.hscan('hsh', 0)
|
607
|
-
results.
|
738
|
+
expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
|
608
739
|
end
|
609
740
|
end
|
610
741
|
end if Redis.current.respond_to?(:hscan)
|
@@ -615,13 +746,13 @@ describe "redis" do
|
|
615
746
|
it 'should yield the correct hash keys unchanged' do
|
616
747
|
results = []
|
617
748
|
@namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
|
618
|
-
results.
|
749
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
619
750
|
end
|
620
751
|
end
|
621
752
|
context 'without a block' do
|
622
753
|
it 'should return an Enumerator that yields the correct hash keys unchanged' do
|
623
754
|
enum = @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000)
|
624
|
-
enum.to_a.
|
755
|
+
expect(enum.to_a).to match_array(hash_matching_subset.to_a)
|
625
756
|
end
|
626
757
|
end
|
627
758
|
end
|
@@ -630,13 +761,13 @@ describe "redis" do
|
|
630
761
|
it 'should yield all hash keys unchanged' do
|
631
762
|
results = []
|
632
763
|
@namespaced.hscan_each('hsh', :count => 1000){ |k| results << k }
|
633
|
-
results.
|
764
|
+
expect(results).to match_array(hash.to_a)
|
634
765
|
end
|
635
766
|
end
|
636
767
|
context 'without a block' do
|
637
768
|
it 'should return an Enumerator that yields all keys unchanged' do
|
638
769
|
enum = @namespaced.hscan_each('hsh', :count => 1000)
|
639
|
-
enum.to_a.
|
770
|
+
expect(enum.to_a).to match_array(hash.to_a)
|
640
771
|
end
|
641
772
|
end
|
642
773
|
end
|
@@ -659,13 +790,13 @@ describe "redis" do
|
|
659
790
|
context 'when supplied :match' do
|
660
791
|
it 'should retrieve the matching set members from the proper set' do
|
661
792
|
_, results = @namespaced.sscan('set', 0, :match => 'zeta:*', :count => 1000)
|
662
|
-
results.
|
793
|
+
expect(results).to match_array(matching_subset)
|
663
794
|
end
|
664
795
|
end
|
665
796
|
context 'without :match supplied' do
|
666
797
|
it 'should retrieve all set members from the proper set' do
|
667
798
|
_, results = @namespaced.sscan('set', 0, :count => 1000)
|
668
|
-
results.
|
799
|
+
expect(results).to match_array(set)
|
669
800
|
end
|
670
801
|
end
|
671
802
|
end if Redis.current.respond_to?(:sscan)
|
@@ -676,13 +807,13 @@ describe "redis" do
|
|
676
807
|
it 'should yield the correct hset elements unchanged' do
|
677
808
|
results = []
|
678
809
|
@namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
|
679
|
-
results.
|
810
|
+
expect(results).to match_array(matching_subset)
|
680
811
|
end
|
681
812
|
end
|
682
813
|
context 'without a block' do
|
683
814
|
it 'should return an Enumerator that yields the correct set elements unchanged' do
|
684
815
|
enum = @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000)
|
685
|
-
enum.to_a.
|
816
|
+
expect(enum.to_a).to match_array(matching_subset)
|
686
817
|
end
|
687
818
|
end
|
688
819
|
end
|
@@ -691,13 +822,13 @@ describe "redis" do
|
|
691
822
|
it 'should yield all set elements unchanged' do
|
692
823
|
results = []
|
693
824
|
@namespaced.sscan_each('set', :count => 1000){ |k| results << k }
|
694
|
-
results.
|
825
|
+
expect(results).to match_array(set)
|
695
826
|
end
|
696
827
|
end
|
697
828
|
context 'without a block' do
|
698
829
|
it 'should return an Enumerator that yields all set elements unchanged' do
|
699
830
|
enum = @namespaced.sscan_each('set', :count => 1000)
|
700
|
-
enum.to_a.
|
831
|
+
expect(enum.to_a).to match_array(set)
|
701
832
|
end
|
702
833
|
end
|
703
834
|
end
|
@@ -721,14 +852,14 @@ describe "redis" do
|
|
721
852
|
it 'should retrieve the matching set elements and their scores' do
|
722
853
|
results = []
|
723
854
|
@namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms }
|
724
|
-
results.
|
855
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
725
856
|
end
|
726
857
|
end
|
727
858
|
context 'without :match supplied' do
|
728
859
|
it 'should retrieve all set elements and their scores' do
|
729
860
|
results = []
|
730
861
|
@namespaced.zscan_each('zset', :count => 1000) { |ms| results << ms }
|
731
|
-
results.
|
862
|
+
expect(results).to match_array(hash.to_a)
|
732
863
|
end
|
733
864
|
end
|
734
865
|
end if Redis.current.respond_to?(:zscan)
|
@@ -739,13 +870,13 @@ describe "redis" do
|
|
739
870
|
it 'should yield the correct set elements and scores unchanged' do
|
740
871
|
results = []
|
741
872
|
@namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms}
|
742
|
-
results.
|
873
|
+
expect(results).to match_array(hash_matching_subset.to_a)
|
743
874
|
end
|
744
875
|
end
|
745
876
|
context 'without a block' do
|
746
877
|
it 'should return an Enumerator that yields the correct set elements and scoresunchanged' do
|
747
878
|
enum = @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000)
|
748
|
-
enum.to_a.
|
879
|
+
expect(enum.to_a).to match_array(hash_matching_subset.to_a)
|
749
880
|
end
|
750
881
|
end
|
751
882
|
end
|
@@ -754,13 +885,13 @@ describe "redis" do
|
|
754
885
|
it 'should yield all set elements and scores unchanged' do
|
755
886
|
results = []
|
756
887
|
@namespaced.zscan_each('zset', :count => 1000){ |ms| results << ms }
|
757
|
-
results.
|
888
|
+
expect(results).to match_array(hash.to_a)
|
758
889
|
end
|
759
890
|
end
|
760
891
|
context 'without a block' do
|
761
892
|
it 'should return an Enumerator that yields all set elements and scores unchanged' do
|
762
893
|
enum = @namespaced.zscan_each('zset', :count => 1000)
|
763
|
-
enum.to_a.
|
894
|
+
expect(enum.to_a).to match_array(hash.to_a)
|
764
895
|
end
|
765
896
|
end
|
766
897
|
end
|
@@ -772,12 +903,12 @@ describe "redis" do
|
|
772
903
|
if @redis_version >= Gem::Version.new("2.8.9")
|
773
904
|
it 'should namespace pfadd' do
|
774
905
|
5.times { |n| @namespaced.pfadd("pf", n) }
|
775
|
-
@redis.pfcount("ns:pf").
|
906
|
+
expect(@redis.pfcount("ns:pf")).to eq(5)
|
776
907
|
end
|
777
908
|
|
778
909
|
it 'should namespace pfcount' do
|
779
910
|
5.times { |n| @redis.pfadd("ns:pf", n) }
|
780
|
-
@namespaced.pfcount("pf").
|
911
|
+
expect(@namespaced.pfcount("pf")).to eq(5)
|
781
912
|
end
|
782
913
|
|
783
914
|
it 'should namespace pfmerge' do
|
@@ -787,7 +918,18 @@ describe "redis" do
|
|
787
918
|
end
|
788
919
|
|
789
920
|
@namespaced.pfmerge("pfc", "pfa", "pfb")
|
790
|
-
@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")
|
791
933
|
end
|
792
934
|
end
|
793
935
|
end
|