redis-namespace 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '08244a1c35f2f0164e72385ebd64aae7c57354b6'
4
- data.tar.gz: dd76131303f0cbb576780146d9c5e3a759302e57
2
+ SHA256:
3
+ metadata.gz: 9ebbb9000d7b34a0a8386ac9d72e2f63f4573720b22a8eb7e3676c0c1759200b
4
+ data.tar.gz: ec5c495b22e58cc98d4c759f7873f2d2f9f69c8205b750062207b6f4b1f45897
5
5
  SHA512:
6
- metadata.gz: 4ca1e49aaf2c9e213a0859d1a0bda67f988ddf3a5af08bbf08388a8582298659d6a6869b7d8ee035501d8abf35779be20164dff5b849110f75f173cafb3444e5
7
- data.tar.gz: ca1151681a327f2206370a12f63729ee4f9a0891830274fc0e219353137f09216757421cfb4d4d29c18f73ca2f6e2b7bcf8ff4a0dc55a88324cd0aa7957f2993
6
+ metadata.gz: e05aa113c14df634a64fdfad7891781ace6a5060a533e9417f94476235f3e05fd33859c4653fcbe8f417582e9257cdf20b1599ac1b2e4cbe38ccaf7c88af2dba
7
+ data.tar.gz: 220e3ec476e5613dd3a8529f2f7b30f7aba9433a1f4ab4402c55be555ef00ff5651738824ddc583e83e7cbad9297d1f1a107bd61e4b44df5e8c9efa50589cfea
data/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
+ MIT License
2
+
1
3
  Copyright (c) 2009 Chris Wanstrath
2
4
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
10
11
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
13
14
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -3,13 +3,13 @@ redis-namespace
3
3
 
4
4
  Redis::Namespace provides an interface to a namespaced subset of your [redis][] keyspace (e.g., keys with a common beginning), and requires the [redis-rb][] gem.
5
5
 
6
- ~~~ irb
6
+ ```ruby
7
7
  require 'redis-namespace'
8
8
  # => true
9
9
 
10
10
  redis_connection = Redis.new
11
11
  # => #<Redis client v3.1.0 for redis://127.0.0.1:6379/0>
12
- namespaced_redis = Redis::Namespace.new(:ns, :redis => redis_connection)
12
+ namespaced_redis = Redis::Namespace.new(:ns, redis: redis_connection)
13
13
  # => #<Redis::Namespace v1.5.0 with client v3.1.0 for redis://127.0.0.1:6379/0/ns>
14
14
 
15
15
  namespaced_redis.set('foo', 'bar') # redis_connection.set('ns:foo', 'bar')
@@ -20,6 +20,8 @@ namespaced_redis.set('foo', 'bar') # redis_connection.set('ns:foo', 'bar')
20
20
 
21
21
  namespaced_redis.get('foo')
22
22
  # => "bar"
23
+ redis_connection.get('foo')
24
+ # => nil
23
25
  redis_connection.get('ns:foo')
24
26
  # => "bar"
25
27
 
@@ -29,7 +31,7 @@ namespaced_redis.get('foo')
29
31
  # => nil
30
32
  redis_connection.get('ns:foo')
31
33
  # => nil
32
- ~~~
34
+ ```
33
35
 
34
36
  Installation
35
37
  ============
@@ -42,20 +44,18 @@ From the command line:
42
44
 
43
45
  Or in your Gemfile:
44
46
 
45
- ~~~ ruby
47
+ ```ruby
46
48
  gem 'redis-namespace'
47
- ~~~
49
+ ```
48
50
 
49
51
  Caveats
50
52
  =======
51
53
 
52
- `Redis::Namespace` provides a namespaced interface to `Redis` by keeping an internal registry of the method signatures in `Redis` provided by the redis-rb gem;
53
- we keep track of which arguments need the namespace added, and which return values need the namespace removed.
54
+ `Redis::Namespace` provides a namespaced interface to `Redis` by keeping an internal registry of the method signatures in `Redis` provided by the [redis-rb][] gem; we keep track of which arguments need the namespace added, and which return values need the namespace removed.
54
55
 
55
56
  Blind Passthrough
56
57
  -----------------
57
- If your version of this gem doesn't know about a particular command, it can't namespace it.
58
- Historically, this has meant that Redis::Namespace blindly passes unknown commands on to the underlying redis connection without modification which can lead to surprising effects.
58
+ If your version of this gem doesn't know about a particular command, it can't namespace it. Historically, this has meant that Redis::Namespace blindly passes unknown commands on to the underlying redis connection without modification which can lead to surprising effects.
59
59
 
60
60
  As of v1.5.0, blind passthrough has been deprecated, and the functionality will be removed entirely in 2.0.
61
61
 
@@ -63,19 +63,16 @@ If you come across a command that is not yet supported, please open an issue on
63
63
 
64
64
  Administrative Commands
65
65
  -----------------------
66
- The effects of some redis commands cannot be limited to a particular namespace (e.g., `FLUSHALL`, which literally truncates all databases in your redis server, regardless of keyspace).
67
- Historically, this has meant that Redis::Namespace intentionally passes administrative commands on to the underlying redis connection without modification, which can lead to surprising effects.
66
+ The effects of some redis commands cannot be limited to a particular namespace (e.g., `FLUSHALL`, which literally truncates all databases in your redis server, regardless of keyspace). Historically, this has meant that Redis::Namespace intentionally passes administrative commands on to the underlying redis connection without modification, which can lead to surprising effects.
68
67
 
69
- As of v1.6.0, the direct use of administrative commands has been deprecated, and the functionality will be removed entirely in 2.0;
70
- while such commands are often useful for testing or administration, their meaning is inherently hidden when placed behind an interface that implies it will namespace everything.
68
+ As of v1.6.0, the direct use of administrative commands has been deprecated, and the functionality will be removed entirely in 2.0; while such commands are often useful for testing or administration, their meaning is inherently hidden when placed behind an interface that implies it will namespace everything.
71
69
 
72
- The prefered way to send an administrative command is on the redis connection
73
- itself, which is publicly exposed as `Redis::Namespace#redis`:
70
+ The prefered way to send an administrative command is on the redis connection itself, which is publicly exposed as `Redis::Namespace#redis`:
74
71
 
75
- ~~~ ruby
72
+ ```ruby
76
73
  namespaced.redis.flushall()
77
74
  # => "OK"
78
- ~~~
75
+ ```
79
76
 
80
77
  2.x Planned Breaking Changes
81
78
  ============================
@@ -57,9 +57,12 @@ class Redis
57
57
  "append" => [ :first ],
58
58
  "bitcount" => [ :first ],
59
59
  "bitop" => [ :exclude_first ],
60
+ "bitpos" => [ :first ],
60
61
  "blpop" => [ :exclude_last, :first ],
61
62
  "brpop" => [ :exclude_last, :first ],
62
63
  "brpoplpush" => [ :exclude_last ],
64
+ "bzpopmin" => [ :first ],
65
+ "bzpopmax" => [ :first ],
63
66
  "debug" => [ :exclude_first ],
64
67
  "decr" => [ :first ],
65
68
  "decrby" => [ :first ],
@@ -160,27 +163,31 @@ class Redis
160
163
  "sunionstore" => [ :all ],
161
164
  "ttl" => [ :first ],
162
165
  "type" => [ :first ],
166
+ "unlink" => [ :all ],
163
167
  "unsubscribe" => [ :all ],
164
168
  "zadd" => [ :first ],
165
169
  "zcard" => [ :first ],
166
170
  "zcount" => [ :first ],
167
171
  "zincrby" => [ :first ],
168
172
  "zinterstore" => [ :exclude_options ],
173
+ "zpopmin" => [ :first ],
174
+ "zpopmax" => [ :first ],
169
175
  "zrange" => [ :first ],
170
176
  "zrangebyscore" => [ :first ],
177
+ "zrangebylex" => [ :first ],
171
178
  "zrank" => [ :first ],
172
179
  "zrem" => [ :first ],
173
180
  "zremrangebyrank" => [ :first ],
174
181
  "zremrangebyscore" => [ :first ],
182
+ "zremrangebylex" => [ :first ],
175
183
  "zrevrange" => [ :first ],
176
184
  "zrevrangebyscore" => [ :first ],
185
+ "zrevrangebylex" => [ :first ],
177
186
  "zrevrank" => [ :first ],
178
187
  "zscan" => [ :first ],
179
188
  "zscan_each" => [ :first ],
180
189
  "zscore" => [ :first ],
181
- "zunionstore" => [ :exclude_options ],
182
- "[]" => [ :first ],
183
- "[]=" => [ :first ]
190
+ "zunionstore" => [ :exclude_options ]
184
191
  }
185
192
  TRANSACTION_COMMANDS = {
186
193
  "discard" => [],
@@ -254,7 +261,7 @@ class Redis
254
261
 
255
262
  def client
256
263
  warn("The client method is deprecated as of redis-rb 4.0.0, please use the new _client" +
257
- "method instead. Support for the old method will be removed in redis-namespace 2.0.") if @has_new_client_method
264
+ "method instead. Support for the old method will be removed in redis-namespace 2.0.") if @has_new_client_method && deprecations?
258
265
  _client
259
266
  end
260
267
 
@@ -272,7 +279,9 @@ class Redis
272
279
 
273
280
  # emulate Ruby 1.9+ and keep respond_to_missing? logic together.
274
281
  def respond_to?(command, include_private=false)
275
- super or respond_to_missing?(command, include_private)
282
+ return !deprecations? if DEPRECATED_COMMANDS.include?(command.to_s.downcase)
283
+
284
+ respond_to_missing?(command, include_private) or super
276
285
  end
277
286
 
278
287
  def keys(query = nil)
@@ -300,6 +309,14 @@ class Redis
300
309
  @namespace
301
310
  end
302
311
 
312
+ def full_namespace
313
+ redis.is_a?(Namespace) ? "#{redis.full_namespace}:#{namespace}" : namespace.to_s
314
+ end
315
+
316
+ def connection
317
+ @redis.connection.tap { |info| info[:namespace] = @namespace }
318
+ end
319
+
303
320
  def exec
304
321
  call_with_namespace(:exec)
305
322
  end
@@ -308,15 +325,12 @@ class Redis
308
325
  call_with_namespace(:eval, *args)
309
326
  end
310
327
 
311
- def method_missing(command, *args, &block)
312
- normalized_command = command.to_s.downcase
328
+ ADMINISTRATIVE_COMMANDS.keys.each do |command|
329
+ define_method(command) do |*args, &block|
330
+ raise NoMethodError if deprecations?
313
331
 
314
- if ADMINISTRATIVE_COMMANDS.include?(normalized_command)
315
- # administrative commands usage is deprecated and will be removed in 2.0
316
- # redis-namespace cannot safely apply a namespace to their effects.
317
- return super if deprecations?
318
332
  if warning?
319
- warn("Passing '#{normalized_command}' command to redis as is; " +
333
+ warn("Passing '#{command}' command to redis as is; " +
320
334
  "administrative commands cannot be effectively namespaced " +
321
335
  "and should be called on the redis connection directly; " +
322
336
  "passthrough has been deprecated and will be removed in " +
@@ -324,8 +338,23 @@ class Redis
324
338
  )
325
339
  end
326
340
  call_with_namespace(command, *args, &block)
327
- elsif COMMANDS.include?(normalized_command)
341
+ end
342
+ end
343
+
344
+ COMMANDS.keys.each do |command|
345
+ next if ADMINISTRATIVE_COMMANDS.include?(command)
346
+ next if method_defined?(command)
347
+
348
+ define_method(command) do |*args, &block|
328
349
  call_with_namespace(command, *args, &block)
350
+ end
351
+ end
352
+
353
+ def method_missing(command, *args, &block)
354
+ normalized_command = command.to_s.downcase
355
+
356
+ if COMMANDS.include?(normalized_command)
357
+ send(normalized_command, *args, &block)
329
358
  elsif @redis.respond_to?(normalized_command) && !deprecations?
330
359
  # blind passthrough is deprecated and will be removed in 2.0
331
360
  # redis-namespace does not know how to handle this command.
@@ -351,8 +380,6 @@ class Redis
351
380
  normalized_command = command.to_s.downcase
352
381
 
353
382
  case
354
- when DEPRECATED_COMMANDS.include?(normalized_command)
355
- !deprecations?
356
383
  when COMMANDS.include?(normalized_command)
357
384
  true
358
385
  when !deprecations? && redis.respond_to?(command, include_all)
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Redis
4
4
  class Namespace
5
- VERSION = '1.6.0'
5
+ VERSION = '1.7.0'
6
6
  end
7
7
  end
@@ -43,7 +43,7 @@ describe Redis::Namespace do
43
43
  its(:deprecations?) { should be true }
44
44
 
45
45
  context('with an unhandled command') do
46
- it { should_not respond_to :unhandled }
46
+ it { is_expected.not_to respond_to :unhandled }
47
47
 
48
48
  it('raises a NoMethodError') do
49
49
  expect do
@@ -53,7 +53,7 @@ describe Redis::Namespace do
53
53
  end
54
54
 
55
55
  context('with an administrative command') do
56
- it { should_not respond_to :flushdb }
56
+ it { is_expected.not_to respond_to :flushdb }
57
57
 
58
58
  it('raises a NoMethodError') do
59
59
  expect do
@@ -69,7 +69,7 @@ describe Redis::Namespace do
69
69
  its(:deprecations?) { should be false }
70
70
 
71
71
  context('with an an unhandled command') do
72
- it { should respond_to :unhandled }
72
+ it { is_expected.to respond_to :unhandled }
73
73
 
74
74
  it 'blindly passes through' do
75
75
  expect(redis).to receive(:unhandled)
@@ -106,7 +106,7 @@ describe Redis::Namespace do
106
106
  end
107
107
 
108
108
  context('with an administrative command') do
109
- it { should respond_to :flushdb }
109
+ it { is_expected.to respond_to :flushdb }
110
110
  it 'processes the command' do
111
111
  expect(redis).to receive(:flushdb)
112
112
  capture_stderr { namespaced.flushdb }
@@ -25,32 +25,38 @@ describe "redis" do
25
25
  @redis.quit
26
26
  end
27
27
 
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
+
28
34
  it "proxies `client` to the _client and deprecated" do
29
- @namespaced.client.should eq(redis_client)
35
+ expect(@namespaced.client).to eq(redis_client)
30
36
  end
31
37
 
32
38
  it "proxies `_client` to the _client" do
33
- @namespaced._client.should eq(redis_client)
39
+ expect(@namespaced._client).to eq(redis_client)
34
40
  end
35
41
 
36
42
  it "should be able to use a namespace" do
37
- @namespaced.get('foo').should eq(nil)
43
+ expect(@namespaced.get('foo')).to eq(nil)
38
44
  @namespaced.set('foo', 'chris')
39
- @namespaced.get('foo').should eq('chris')
45
+ expect(@namespaced.get('foo')).to eq('chris')
40
46
  @redis.set('foo', 'bob')
41
- @redis.get('foo').should eq('bob')
47
+ expect(@redis.get('foo')).to eq('bob')
42
48
 
43
49
  @namespaced.incrby('counter', 2)
44
- @namespaced.get('counter').to_i.should eq(2)
45
- @redis.get('counter').should eq(nil)
46
- @namespaced.type('counter').should eq('string')
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')
47
53
  end
48
54
 
49
55
  context 'when sending capital commands (issue 68)' do
50
56
  it 'should be able to use a namespace' do
51
57
  @namespaced.send('SET', 'fubar', 'quux')
52
- @redis.get('fubar').should be_nil
53
- @namespaced.get('fubar').should eq 'quux'
58
+ expect(@redis.get('fubar')).to be_nil
59
+ expect(@namespaced.get('fubar')).to eq 'quux'
54
60
  end
55
61
  end
56
62
 
@@ -58,10 +64,10 @@ describe "redis" do
58
64
  @namespaced.rpush "foo", "string"
59
65
  @namespaced.rpush "foo", "ns:string"
60
66
  @namespaced.rpush "foo", "string_no_timeout"
61
- @namespaced.blpop("foo", 1).should eq(["foo", "string"])
62
- @namespaced.blpop("foo", 1).should eq(["foo", "ns:string"])
63
- @namespaced.blpop("foo").should eq(["foo", "string_no_timeout"])
64
- @namespaced.blpop("foo", 1).should eq(nil)
67
+ expect(@namespaced.blpop("foo", 1)).to eq(["foo", "string"])
68
+ expect(@namespaced.blpop("foo", 1)).to eq(["foo", "ns:string"])
69
+ expect(@namespaced.blpop("foo")).to eq(["foo", "string_no_timeout"])
70
+ expect(@namespaced.blpop("foo", 1)).to eq(nil)
65
71
  end
66
72
 
67
73
  it "should be able to use a namespace with del" do
@@ -69,125 +75,142 @@ describe "redis" do
69
75
  @namespaced.set('bar', 2000)
70
76
  @namespaced.set('baz', 3000)
71
77
  @namespaced.del 'foo'
72
- @namespaced.get('foo').should eq(nil)
78
+ expect(@namespaced.get('foo')).to eq(nil)
73
79
  @namespaced.del 'bar', 'baz'
74
- @namespaced.get('bar').should eq(nil)
75
- @namespaced.get('baz').should eq(nil)
80
+ expect(@namespaced.get('bar')).to eq(nil)
81
+ expect(@namespaced.get('baz')).to eq(nil)
82
+ end
83
+
84
+ it "should be able to use a namespace with unlink" do
85
+ @namespaced.set('foo', 1000)
86
+ @namespaced.set('bar', 2000)
87
+ @namespaced.set('baz', 3000)
88
+ @namespaced.unlink 'foo'
89
+ expect(@namespaced.get('foo')).to eq(nil)
90
+ @namespaced.unlink 'bar', 'baz'
91
+ expect(@namespaced.get('bar')).to eq(nil)
92
+ expect(@namespaced.get('baz')).to eq(nil)
76
93
  end
77
94
 
78
95
  it 'should be able to use a namespace with append' do
79
96
  @namespaced.set('foo', 'bar')
80
- @namespaced.append('foo','n').should eq(4)
81
- @namespaced.get('foo').should eq('barn')
82
- @redis.get('foo').should eq('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')
83
100
  end
84
101
 
85
102
  it 'should be able to use a namespace with brpoplpush' do
86
103
  @namespaced.lpush('foo','bar')
87
- @namespaced.brpoplpush('foo','bar',0).should eq('bar')
88
- @namespaced.lrange('foo',0,-1).should eq([])
89
- @namespaced.lrange('bar',0,-1).should eq(['bar'])
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'])
90
107
  end
91
108
 
92
109
  it 'should be able to use a namespace with getbit' do
93
110
  @namespaced.set('foo','bar')
94
- @namespaced.getbit('foo',1).should eq(1)
111
+ expect(@namespaced.getbit('foo',1)).to eq(1)
95
112
  end
96
113
 
97
114
  it 'should be able to use a namespace with getrange' do
98
115
  @namespaced.set('foo','bar')
99
- @namespaced.getrange('foo',0,-1).should eq('bar')
116
+ expect(@namespaced.getrange('foo',0,-1)).to eq('bar')
100
117
  end
101
118
 
102
119
  it 'should be able to use a namespace with linsert' do
103
120
  @namespaced.rpush('foo','bar')
104
121
  @namespaced.rpush('foo','barn')
105
122
  @namespaced.rpush('foo','bart')
106
- @namespaced.linsert('foo','BEFORE','barn','barf').should eq(4)
107
- @namespaced.lrange('foo',0,-1).should eq(['bar','barf','barn','bart'])
123
+ expect(@namespaced.linsert('foo','BEFORE','barn','barf')).to eq(4)
124
+ expect(@namespaced.lrange('foo',0,-1)).to eq(['bar','barf','barn','bart'])
108
125
  end
109
126
 
110
127
  it 'should be able to use a namespace with lpushx' do
111
- @namespaced.lpushx('foo','bar').should eq(0)
128
+ expect(@namespaced.lpushx('foo','bar')).to eq(0)
112
129
  @namespaced.lpush('foo','boo')
113
- @namespaced.lpushx('foo','bar').should eq(2)
114
- @namespaced.lrange('foo',0,-1).should eq(['bar','boo'])
130
+ expect(@namespaced.lpushx('foo','bar')).to eq(2)
131
+ expect(@namespaced.lrange('foo',0,-1)).to eq(['bar','boo'])
115
132
  end
116
133
 
117
134
  it 'should be able to use a namespace with rpushx' do
118
- @namespaced.rpushx('foo','bar').should eq(0)
135
+ expect(@namespaced.rpushx('foo','bar')).to eq(0)
119
136
  @namespaced.lpush('foo','boo')
120
- @namespaced.rpushx('foo','bar').should eq(2)
121
- @namespaced.lrange('foo',0,-1).should eq(['boo','bar'])
137
+ expect(@namespaced.rpushx('foo','bar')).to eq(2)
138
+ expect(@namespaced.lrange('foo',0,-1)).to eq(['boo','bar'])
122
139
  end
123
140
 
124
141
  it 'should be able to use a namespace with setbit' do
125
142
  @namespaced.setbit('virgin_key', 1, 1)
126
- @namespaced.exists('virgin_key').should be_true
127
- @namespaced.get('virgin_key').should eq(@namespaced.getrange('virgin_key',0,-1))
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 bitpos' do
148
+ @namespaced.setbit('bit_map', 42, 1)
149
+ expect(@namespaced.bitpos('bit_map', 0)).to eq(0)
150
+ expect(@namespaced.bitpos('bit_map', 1)).to eq(42)
128
151
  end
129
152
 
130
153
  it 'should be able to use a namespace with setrange' do
131
154
  @namespaced.setrange('foo', 0, 'bar')
132
- @namespaced.get('foo').should eq('bar')
155
+ expect(@namespaced.get('foo')).to eq('bar')
133
156
 
134
157
  @namespaced.setrange('bar', 2, 'foo')
135
- @namespaced.get('bar').should eq("\000\000foo")
158
+ expect(@namespaced.get('bar')).to eq("\000\000foo")
136
159
  end
137
160
 
138
161
  it "should be able to use a namespace with mget" do
139
162
  @namespaced.set('foo', 1000)
140
163
  @namespaced.set('bar', 2000)
141
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000' })
142
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
164
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
165
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
143
166
  end
144
167
 
145
168
  it "should be able to use a namespace with mset" do
146
169
  @namespaced.mset('foo', '1000', 'bar', '2000')
147
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000' })
148
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
170
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
171
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
149
172
  @namespaced.mapped_mset('foo' => '3000', 'bar' => '5000')
150
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '3000', 'bar' => '5000' })
151
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
173
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000' })
174
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
152
175
  end
153
176
 
154
177
  it "should be able to use a namespace with msetnx" do
155
178
  @namespaced.msetnx('foo', '1000', 'bar', '2000')
156
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000' })
157
- @namespaced.mapped_mget('foo', 'baz', 'bar').should eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
179
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
180
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
158
181
  end
159
182
 
160
183
  it "should be able to use a namespace with mapped_msetnx" do
161
184
  @namespaced.set('foo','1')
162
- @namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000').should be_false
163
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1', 'bar' => nil })
164
- @namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000').should be_true
165
- @namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1', 'bar' => '2000' })
185
+ expect(@namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000')).to be false
186
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1', 'bar' => nil })
187
+ expect(@namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000')).to be true
188
+ expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1', 'bar' => '2000' })
166
189
  end
167
190
 
168
191
  it "should be able to use a namespace with hashes" do
169
192
  @namespaced.hset('foo', 'key', 'value')
170
193
  @namespaced.hset('foo', 'key1', 'value1')
171
- @namespaced.hget('foo', 'key').should eq('value')
172
- @namespaced.hgetall('foo').should eq({'key' => 'value', 'key1' => 'value1'})
173
- @namespaced.hlen('foo').should eq(2)
174
- @namespaced.hkeys('foo').should eq(['key', 'key1'])
194
+ expect(@namespaced.hget('foo', 'key')).to eq('value')
195
+ expect(@namespaced.hgetall('foo')).to eq({'key' => 'value', 'key1' => 'value1'})
196
+ expect(@namespaced.hlen('foo')).to eq(2)
197
+ expect(@namespaced.hkeys('foo')).to eq(['key', 'key1'])
175
198
  @namespaced.hmset('bar', 'key', 'value', 'key1', 'value1')
176
199
  @namespaced.hmget('bar', 'key', 'key1')
177
200
  @namespaced.hmset('bar', 'a_number', 1)
178
- @namespaced.hmget('bar', 'a_number').should eq(['1'])
201
+ expect(@namespaced.hmget('bar', 'a_number')).to eq(['1'])
179
202
  @namespaced.hincrby('bar', 'a_number', 3)
180
- @namespaced.hmget('bar', 'a_number').should eq(['4'])
181
- @namespaced.hgetall('bar').should eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
182
-
183
- @namespaced.hsetnx('foonx','nx',10).should be_true
184
- @namespaced.hsetnx('foonx','nx',12).should be_false
185
- @namespaced.hget('foonx','nx').should eq("10")
186
- @namespaced.hkeys('foonx').should eq(%w{ nx })
187
- @namespaced.hvals('foonx').should eq(%w{ 10 })
203
+ expect(@namespaced.hmget('bar', 'a_number')).to eq(['4'])
204
+ expect(@namespaced.hgetall('bar')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
205
+
206
+ expect(@namespaced.hsetnx('foonx','nx',10)).to be true
207
+ expect(@namespaced.hsetnx('foonx','nx',12)).to be false
208
+ expect(@namespaced.hget('foonx','nx')).to eq("10")
209
+ expect(@namespaced.hkeys('foonx')).to eq(%w{ nx })
210
+ expect(@namespaced.hvals('foonx')).to eq(%w{ 10 })
188
211
  @namespaced.mapped_hmset('baz', {'key' => 'value', 'key1' => 'value1', 'a_number' => 4})
189
- @namespaced.mapped_hmget('baz', 'key', 'key1', 'a_number').should eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
190
- @namespaced.hgetall('baz').should eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
212
+ expect(@namespaced.mapped_hmget('baz', 'key', 'key1', 'a_number')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
213
+ expect(@namespaced.hgetall('baz')).to eq({'key' => 'value', 'key1' => 'value1', 'a_number' => '4'})
191
214
  end
192
215
 
193
216
  it "should properly intersect three sets" do
@@ -198,7 +221,7 @@ describe "redis" do
198
221
  @namespaced.sadd('bar', 3)
199
222
  @namespaced.sadd('bar', 4)
200
223
  @namespaced.sadd('baz', 3)
201
- @namespaced.sinter('foo', 'bar', 'baz').should eq(%w( 3 ))
224
+ expect(@namespaced.sinter('foo', 'bar', 'baz')).to eq(%w( 3 ))
202
225
  end
203
226
 
204
227
  it "should properly union two sets" do
@@ -207,7 +230,7 @@ describe "redis" do
207
230
  @namespaced.sadd('bar', 2)
208
231
  @namespaced.sadd('bar', 3)
209
232
  @namespaced.sadd('bar', 4)
210
- @namespaced.sunion('foo', 'bar').sort.should eq(%w( 1 2 3 4 ))
233
+ expect(@namespaced.sunion('foo', 'bar').sort).to eq(%w( 1 2 3 4 ))
211
234
  end
212
235
 
213
236
  it "should properly union two sorted sets with options" do
@@ -217,7 +240,7 @@ describe "redis" do
217
240
  @namespaced.zadd('sort2', 3, 3)
218
241
  @namespaced.zadd('sort2', 4, 4)
219
242
  @namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1])
220
- @namespaced.zrevrange('union', 0, -1).should eq(%w( 2 4 3 1 ))
243
+ expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
221
244
  end
222
245
 
223
246
  it "should properly union two sorted sets without options" do
@@ -227,7 +250,7 @@ describe "redis" do
227
250
  @namespaced.zadd('sort2', 3, 3)
228
251
  @namespaced.zadd('sort2', 4, 4)
229
252
  @namespaced.zunionstore('union', ['sort1', 'sort2'])
230
- @namespaced.zrevrange('union', 0, -1).should eq(%w( 4 2 3 1 ))
253
+ expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 4 2 3 1 ))
231
254
  end
232
255
 
233
256
  it "should properly intersect two sorted sets without options" do
@@ -242,7 +265,7 @@ describe "redis" do
242
265
  @namespaced.zinterstore('inter', ['food', 'color'])
243
266
 
244
267
  inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
245
- inter_values.should =~ [['orange', 3.0], ['eggplant', 7.0]]
268
+ expect(inter_values).to match_array([['orange', 3.0], ['eggplant', 7.0]])
246
269
  end
247
270
 
248
271
  it "should properly intersect two sorted sets with options" do
@@ -257,7 +280,37 @@ describe "redis" do
257
280
  @namespaced.zinterstore('inter', ['food', 'color'], :aggregate => "min")
258
281
 
259
282
  inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
260
- inter_values.should =~ [['orange', 1.0], ['eggplant', 3.0]]
283
+ expect(inter_values).to match_array([['orange', 1.0], ['eggplant', 3.0]])
284
+ end
285
+
286
+ it "should return lexicographical range for sorted set" do
287
+ @namespaced.zadd('food', 0, 'orange')
288
+ @namespaced.zadd('food', 0, 'banana')
289
+ @namespaced.zadd('food', 0, 'eggplant')
290
+
291
+ values = @namespaced.zrangebylex('food', '[b', '(o')
292
+ expect(values).to match_array(['banana', 'eggplant'])
293
+ end
294
+
295
+ it "should return the number of elements removed from the set" do
296
+ @namespaced.zadd('food', 0, 'orange')
297
+ @namespaced.zadd('food', 0, 'banana')
298
+ @namespaced.zadd('food', 0, 'eggplant')
299
+
300
+ removed = @namespaced.zremrangebylex('food', '[b', '(o')
301
+ expect(removed).to eq(2)
302
+
303
+ values = @namespaced.zrange('food', 0, -1)
304
+ expect(values).to eq(['orange'])
305
+ end
306
+
307
+ it "should return reverce lexicographical range for sorted set" do
308
+ @namespaced.zadd('food', 0, 'orange')
309
+ @namespaced.zadd('food', 0, 'banana')
310
+ @namespaced.zadd('food', 0, 'eggplant')
311
+
312
+ values = @namespaced.zrevrangebylex('food', '(o', '[b')
313
+ expect(values).to match_array(['banana', 'eggplant'])
261
314
  end
262
315
 
263
316
  it "should add namespace to sort" do
@@ -268,24 +321,24 @@ describe "redis" do
268
321
  @namespaced.set('value_1', 'a')
269
322
  @namespaced.set('value_2', 'b')
270
323
 
271
- @namespaced.sort('foo').should eq(%w( 1 2 ))
272
- @namespaced.sort('foo', :limit => [0, 1]).should eq(%w( 1 ))
273
- @namespaced.sort('foo', :order => 'desc').should eq(%w( 2 1 ))
274
- @namespaced.sort('foo', :by => 'weight_*').should eq(%w( 2 1 ))
275
- @namespaced.sort('foo', :get => 'value_*').should eq(%w( a b ))
276
- @namespaced.sort('foo', :get => '#').should eq(%w( 1 2 ))
277
- @namespaced.sort('foo', :get => ['#', 'value_*']).should eq([["1", "a"], ["2", "b"]])
324
+ expect(@namespaced.sort('foo')).to eq(%w( 1 2 ))
325
+ expect(@namespaced.sort('foo', :limit => [0, 1])).to eq(%w( 1 ))
326
+ expect(@namespaced.sort('foo', :order => 'desc')).to eq(%w( 2 1 ))
327
+ expect(@namespaced.sort('foo', :by => 'weight_*')).to eq(%w( 2 1 ))
328
+ expect(@namespaced.sort('foo', :get => 'value_*')).to eq(%w( a b ))
329
+ expect(@namespaced.sort('foo', :get => '#')).to eq(%w( 1 2 ))
330
+ expect(@namespaced.sort('foo', :get => ['#', 'value_*'])).to eq([["1", "a"], ["2", "b"]])
278
331
 
279
332
  @namespaced.sort('foo', :store => 'result')
280
- @namespaced.lrange('result', 0, -1).should eq(%w( 1 2 ))
333
+ expect(@namespaced.lrange('result', 0, -1)).to eq(%w( 1 2 ))
281
334
  end
282
335
 
283
336
  it "should yield the correct list of keys" do
284
337
  @namespaced.set("foo", 1)
285
338
  @namespaced.set("bar", 2)
286
339
  @namespaced.set("baz", 3)
287
- @namespaced.keys("*").sort.should eq(%w( bar baz foo ))
288
- @namespaced.keys.sort.should eq(%w( bar baz foo ))
340
+ expect(@namespaced.keys("*").sort).to eq(%w( bar baz foo ))
341
+ expect(@namespaced.keys.sort).to eq(%w( bar baz foo ))
289
342
  end
290
343
 
291
344
  it "should add namepsace to multi blocks" do
@@ -294,7 +347,7 @@ describe "redis" do
294
347
  r.del "foo"
295
348
  r.mapped_hmset "foo", {"key1" => "value1"}
296
349
  end
297
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
350
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
298
351
  end
299
352
 
300
353
  it "should pass through multi commands without block" do
@@ -305,14 +358,14 @@ describe "redis" do
305
358
  @namespaced.mapped_hmset "foo", {"key1" => "value1"}
306
359
  @namespaced.exec
307
360
 
308
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
361
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
309
362
  end
310
363
 
311
364
  it 'should return futures without attempting to remove namespaces' do
312
365
  @namespaced.multi do
313
366
  @future = @namespaced.keys('*')
314
367
  end
315
- @future.class.should be(Redis::Future)
368
+ expect(@future.class).to be(Redis::Future)
316
369
  end
317
370
 
318
371
  it "should add namespace to pipelined blocks" do
@@ -321,7 +374,7 @@ describe "redis" do
321
374
  r.del "foo"
322
375
  r.mapped_hmset "foo", {"key1" => "value1"}
323
376
  end
324
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
377
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
325
378
  end
326
379
 
327
380
  it "should returned response array from pipelined block" do
@@ -330,59 +383,59 @@ describe "redis" do
330
383
  r.get("foo")
331
384
  r.get("key")
332
385
  end
333
- result.should eq(["bar", "value"])
386
+ expect(result).to eq(["bar", "value"])
334
387
  end
335
388
 
336
389
  it "should add namespace to strlen" do
337
390
  @namespaced.set("mykey", "123456")
338
- @namespaced.strlen("mykey").should eq(6)
391
+ expect(@namespaced.strlen("mykey")).to eq(6)
339
392
  end
340
393
 
341
394
  it "should not add namespace to echo" do
342
- @namespaced.echo(123).should eq("123")
395
+ expect(@namespaced.echo(123)).to eq("123")
343
396
  end
344
397
 
345
398
  it 'should not add namespace to disconnect!' do
346
- expect(@redis).to receive(:disconnect!).with().and_call_original
399
+ expect(@redis).to receive(:disconnect!).with(no_args).and_call_original
347
400
 
348
401
  expect(@namespaced.disconnect!).to be nil
349
402
  end
350
403
 
351
404
  it "can change its namespace" do
352
- @namespaced.get('foo').should eq(nil)
405
+ expect(@namespaced.get('foo')).to eq(nil)
353
406
  @namespaced.set('foo', 'chris')
354
- @namespaced.get('foo').should eq('chris')
407
+ expect(@namespaced.get('foo')).to eq('chris')
355
408
 
356
- @namespaced.namespace.should eq(:ns)
409
+ expect(@namespaced.namespace).to eq(:ns)
357
410
  @namespaced.namespace = :spec
358
- @namespaced.namespace.should eq(:spec)
411
+ expect(@namespaced.namespace).to eq(:spec)
359
412
 
360
- @namespaced.get('foo').should eq(nil)
413
+ expect(@namespaced.get('foo')).to eq(nil)
361
414
  @namespaced.set('foo', 'chris')
362
- @namespaced.get('foo').should eq('chris')
415
+ expect(@namespaced.get('foo')).to eq('chris')
363
416
  end
364
417
 
365
418
  it "can accept a temporary namespace" do
366
- @namespaced.namespace.should eq(:ns)
367
- @namespaced.get('foo').should eq(nil)
419
+ expect(@namespaced.namespace).to eq(:ns)
420
+ expect(@namespaced.get('foo')).to eq(nil)
368
421
 
369
422
  @namespaced.namespace(:spec) do |temp_ns|
370
- temp_ns.namespace.should eq(:spec)
371
- temp_ns.get('foo').should eq(nil)
423
+ expect(temp_ns.namespace).to eq(:spec)
424
+ expect(temp_ns.get('foo')).to eq(nil)
372
425
  temp_ns.set('foo', 'jake')
373
- temp_ns.get('foo').should eq('jake')
426
+ expect(temp_ns.get('foo')).to eq('jake')
374
427
  end
375
428
 
376
- @namespaced.namespace.should eq(:ns)
377
- @namespaced.get('foo').should eq(nil)
429
+ expect(@namespaced.namespace).to eq(:ns)
430
+ expect(@namespaced.get('foo')).to eq(nil)
378
431
  end
379
432
 
380
433
  it "should respond to :namespace=" do
381
- @namespaced.respond_to?(:namespace=).should eq(true)
434
+ expect(@namespaced.respond_to?(:namespace=)).to eq(true)
382
435
  end
383
436
 
384
437
  it "should respond to :warning=" do
385
- @namespaced.respond_to?(:warning=).should == true
438
+ expect(@namespaced.respond_to?(:warning=)).to eq(true)
386
439
  end
387
440
 
388
441
  it "should raise an exception when an unknown command is passed" do
@@ -422,7 +475,7 @@ describe "redis" do
422
475
  v = @namespaced.dump("foo")
423
476
  @redis.del("ns:foo")
424
477
 
425
- expect(@namespaced.restore("foo", 1000, v)).to be_true
478
+ expect(@namespaced.restore("foo", 1000, v)).to be_truthy
426
479
  expect(@redis.get("ns:foo")).to eq 'a'
427
480
  expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
428
481
 
@@ -430,72 +483,72 @@ describe "redis" do
430
483
  w = @namespaced.dump("bar")
431
484
  @redis.del("ns:bar")
432
485
 
433
- expect(@namespaced.restore("bar", 1000, w)).to be_true
486
+ expect(@namespaced.restore("bar", 1000, w)).to be_truthy
434
487
  expect(@redis.lrange('ns:bar', 0, -1)).to eq %w(b c d)
435
488
  expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
436
489
  end
437
490
 
438
491
  it "should namespace hincrbyfloat" do
439
492
  @namespaced.hset('mykey', 'field', 10.50)
440
- @namespaced.hincrbyfloat('mykey', 'field', 0.1).should eq(10.6)
493
+ expect(@namespaced.hincrbyfloat('mykey', 'field', 0.1)).to eq(10.6)
441
494
  end
442
495
 
443
496
  it "should namespace incrbyfloat" do
444
497
  @namespaced.set('mykey', 10.50)
445
- @namespaced.incrbyfloat('mykey', 0.1).should eq(10.6)
498
+ expect(@namespaced.incrbyfloat('mykey', 0.1)).to eq(10.6)
446
499
  end
447
500
 
448
501
  it "should namespace object" do
449
502
  @namespaced.set('foo', 1000)
450
- @namespaced.object('encoding', 'foo').should eq('int')
503
+ expect(@namespaced.object('encoding', 'foo')).to eq('int')
451
504
  end
452
505
 
453
506
  it "should namespace persist" do
454
507
  @namespaced.set('mykey', 'Hello')
455
508
  @namespaced.expire('mykey', 60)
456
- @namespaced.persist('mykey').should eq(true)
457
- @namespaced.ttl('mykey').should eq(-1)
509
+ expect(@namespaced.persist('mykey')).to eq(true)
510
+ expect(@namespaced.ttl('mykey')).to eq(-1)
458
511
  end
459
512
 
460
513
  it "should namespace pexpire" do
461
514
  @namespaced.set('mykey', 'Hello')
462
- @namespaced.pexpire('mykey', 60000).should eq(true)
515
+ expect(@namespaced.pexpire('mykey', 60000)).to eq(true)
463
516
  end
464
517
 
465
518
  it "should namespace pexpireat" do
466
519
  @namespaced.set('mykey', 'Hello')
467
- @namespaced.pexpire('mykey', 1555555555005).should eq(true)
520
+ expect(@namespaced.pexpire('mykey', 1555555555005)).to eq(true)
468
521
  end
469
522
 
470
523
  it "should namespace psetex" do
471
- @namespaced.psetex('mykey', 10000, 'Hello').should eq('OK')
472
- @namespaced.get('mykey').should eq('Hello')
524
+ expect(@namespaced.psetex('mykey', 10000, 'Hello')).to eq('OK')
525
+ expect(@namespaced.get('mykey')).to eq('Hello')
473
526
  end
474
527
 
475
528
  it "should namespace pttl" do
476
529
  @namespaced.set('mykey', 'Hello')
477
530
  @namespaced.expire('mykey', 1)
478
- @namespaced.pttl('mykey').should >= 0
531
+ expect(@namespaced.pttl('mykey')).to be >= 0
479
532
  end
480
533
 
481
534
  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
- should eq(%w[ns:k1 ns:k2])
535
+ expect(@namespaced.
536
+ eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2])).
537
+ to eq(%w[ns:k1 ns:k2])
485
538
  end
486
539
 
487
540
  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
- should eq(%w[ns:k1 ns:k2])
541
+ expect(@namespaced.
542
+ eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
543
+ to eq(%w[ns:k1 ns:k2])
491
544
  end
492
545
 
493
546
  it "should namespace eval keys passed in as hash args unmodified" do
494
547
  args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
495
548
  args.freeze
496
- @namespaced.
497
- eval("return {KEYS[1], KEYS[2]}", args).
498
- should eq(%w[ns:k1 ns:k2])
549
+ expect(@namespaced.
550
+ eval("return {KEYS[1], KEYS[2]}", args)).
551
+ to eq(%w[ns:k1 ns:k2])
499
552
  end
500
553
 
501
554
  context '#evalsha' do
@@ -504,23 +557,23 @@ describe "redis" do
504
557
  end
505
558
 
506
559
  it "should namespace evalsha keys passed in as array args" do
507
- @namespaced.
508
- evalsha(sha, %w[k1 k2], %w[arg1 arg2]).
509
- should eq(%w[ns:k1 ns:k2])
560
+ expect(@namespaced.
561
+ evalsha(sha, %w[k1 k2], %w[arg1 arg2])).
562
+ to eq(%w[ns:k1 ns:k2])
510
563
  end
511
564
 
512
565
  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
- should eq(%w[ns:k1 ns:k2])
566
+ expect(@namespaced.
567
+ evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
568
+ to eq(%w[ns:k1 ns:k2])
516
569
  end
517
570
 
518
571
  it "should namespace evalsha keys passed in as hash args unmodified" do
519
572
  args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
520
573
  args.freeze
521
- @namespaced.
522
- evalsha(sha, args).
523
- should eq(%w[ns:k1 ns:k2])
574
+ expect(@namespaced.
575
+ evalsha(sha, args)).
576
+ to eq(%w[ns:k1 ns:k2])
524
577
  end
525
578
  end
526
579
 
@@ -529,13 +582,13 @@ describe "redis" do
529
582
  let(:sha) { @redis.script(:load, "return {KEYS[1], KEYS[2]}") }
530
583
 
531
584
  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
- should eq(%w[ns:nest:k1 ns:nest:k2])
585
+ expect(nested_namespace.
586
+ eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
587
+ to eq(%w[ns:nest:k1 ns:nest:k2])
535
588
  end
536
589
  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
- should eq(%w[ns:nest:k1 ns:nest:k2])
590
+ expect(nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
591
+ to eq(%w[ns:nest:k1 ns:nest:k2])
539
592
  end
540
593
  end
541
594
  end
@@ -564,13 +617,13 @@ describe "redis" do
564
617
  context 'when :match supplied' do
565
618
  it 'should retrieve the proper keys' do
566
619
  _, result = @namespaced.scan(0, :match => 'zeta:*', :count => 1000)
567
- result.should =~ matching_namespaced_keys
620
+ expect(result).to match_array(matching_namespaced_keys)
568
621
  end
569
622
  end
570
623
  context 'without :match supplied' do
571
624
  it 'should retrieve the proper keys' do
572
625
  _, result = @namespaced.scan(0, :count => 1000)
573
- result.should =~ namespaced_keys
626
+ expect(result).to match_array(namespaced_keys)
574
627
  end
575
628
  end
576
629
  end if Redis.current.respond_to?(:scan)
@@ -581,13 +634,13 @@ describe "redis" do
581
634
  it 'should yield unnamespaced' do
582
635
  results = []
583
636
  @namespaced.scan_each(:match => 'zeta:*', :count => 1000) {|k| results << k }
584
- results.should =~ matching_namespaced_keys
637
+ expect(results).to match_array(matching_namespaced_keys)
585
638
  end
586
639
  end
587
640
  context 'without a block' do
588
641
  it 'should return an Enumerator that un-namespaces' do
589
642
  enum = @namespaced.scan_each(:match => 'zeta:*', :count => 1000)
590
- enum.to_a.should =~ matching_namespaced_keys
643
+ expect(enum.to_a).to match_array(matching_namespaced_keys)
591
644
  end
592
645
  end
593
646
  end
@@ -596,13 +649,13 @@ describe "redis" do
596
649
  it 'should yield unnamespaced' do
597
650
  results = []
598
651
  @namespaced.scan_each(:count => 1000){ |k| results << k }
599
- results.should =~ namespaced_keys
652
+ expect(results).to match_array(namespaced_keys)
600
653
  end
601
654
  end
602
655
  context 'without a block' do
603
656
  it 'should return an Enumerator that un-namespaces' do
604
657
  enum = @namespaced.scan_each(:count => 1000)
605
- enum.to_a.should =~ namespaced_keys
658
+ expect(enum.to_a).to match_array(namespaced_keys)
606
659
  end
607
660
  end
608
661
  end
@@ -625,13 +678,13 @@ describe "redis" do
625
678
  context 'when supplied :match' do
626
679
  it 'should retrieve the proper keys' do
627
680
  _, results = @namespaced.hscan('hsh', 0, :match => 'zeta:*')
628
- results.should =~ hash_matching_subset.to_a
681
+ expect(results).to match_array(hash_matching_subset.to_a)
629
682
  end
630
683
  end
631
684
  context 'without :match supplied' do
632
685
  it 'should retrieve all hash keys' do
633
686
  _, results = @namespaced.hscan('hsh', 0)
634
- results.should =~ @redis.hgetall('ns:hsh').to_a
687
+ expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
635
688
  end
636
689
  end
637
690
  end if Redis.current.respond_to?(:hscan)
@@ -642,13 +695,13 @@ describe "redis" do
642
695
  it 'should yield the correct hash keys unchanged' do
643
696
  results = []
644
697
  @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
645
- results.should =~ hash_matching_subset.to_a
698
+ expect(results).to match_array(hash_matching_subset.to_a)
646
699
  end
647
700
  end
648
701
  context 'without a block' do
649
702
  it 'should return an Enumerator that yields the correct hash keys unchanged' do
650
703
  enum = @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000)
651
- enum.to_a.should =~ hash_matching_subset.to_a
704
+ expect(enum.to_a).to match_array(hash_matching_subset.to_a)
652
705
  end
653
706
  end
654
707
  end
@@ -657,13 +710,13 @@ describe "redis" do
657
710
  it 'should yield all hash keys unchanged' do
658
711
  results = []
659
712
  @namespaced.hscan_each('hsh', :count => 1000){ |k| results << k }
660
- results.should =~ hash.to_a
713
+ expect(results).to match_array(hash.to_a)
661
714
  end
662
715
  end
663
716
  context 'without a block' do
664
717
  it 'should return an Enumerator that yields all keys unchanged' do
665
718
  enum = @namespaced.hscan_each('hsh', :count => 1000)
666
- enum.to_a.should =~ hash.to_a
719
+ expect(enum.to_a).to match_array(hash.to_a)
667
720
  end
668
721
  end
669
722
  end
@@ -686,13 +739,13 @@ describe "redis" do
686
739
  context 'when supplied :match' do
687
740
  it 'should retrieve the matching set members from the proper set' do
688
741
  _, results = @namespaced.sscan('set', 0, :match => 'zeta:*', :count => 1000)
689
- results.should =~ matching_subset
742
+ expect(results).to match_array(matching_subset)
690
743
  end
691
744
  end
692
745
  context 'without :match supplied' do
693
746
  it 'should retrieve all set members from the proper set' do
694
747
  _, results = @namespaced.sscan('set', 0, :count => 1000)
695
- results.should =~ set
748
+ expect(results).to match_array(set)
696
749
  end
697
750
  end
698
751
  end if Redis.current.respond_to?(:sscan)
@@ -703,13 +756,13 @@ describe "redis" do
703
756
  it 'should yield the correct hset elements unchanged' do
704
757
  results = []
705
758
  @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
706
- results.should =~ matching_subset
759
+ expect(results).to match_array(matching_subset)
707
760
  end
708
761
  end
709
762
  context 'without a block' do
710
763
  it 'should return an Enumerator that yields the correct set elements unchanged' do
711
764
  enum = @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000)
712
- enum.to_a.should =~ matching_subset
765
+ expect(enum.to_a).to match_array(matching_subset)
713
766
  end
714
767
  end
715
768
  end
@@ -718,13 +771,13 @@ describe "redis" do
718
771
  it 'should yield all set elements unchanged' do
719
772
  results = []
720
773
  @namespaced.sscan_each('set', :count => 1000){ |k| results << k }
721
- results.should =~ set
774
+ expect(results).to match_array(set)
722
775
  end
723
776
  end
724
777
  context 'without a block' do
725
778
  it 'should return an Enumerator that yields all set elements unchanged' do
726
779
  enum = @namespaced.sscan_each('set', :count => 1000)
727
- enum.to_a.should =~ set
780
+ expect(enum.to_a).to match_array(set)
728
781
  end
729
782
  end
730
783
  end
@@ -748,14 +801,14 @@ describe "redis" do
748
801
  it 'should retrieve the matching set elements and their scores' do
749
802
  results = []
750
803
  @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms }
751
- results.should =~ hash_matching_subset.to_a
804
+ expect(results).to match_array(hash_matching_subset.to_a)
752
805
  end
753
806
  end
754
807
  context 'without :match supplied' do
755
808
  it 'should retrieve all set elements and their scores' do
756
809
  results = []
757
810
  @namespaced.zscan_each('zset', :count => 1000) { |ms| results << ms }
758
- results.should =~ hash.to_a
811
+ expect(results).to match_array(hash.to_a)
759
812
  end
760
813
  end
761
814
  end if Redis.current.respond_to?(:zscan)
@@ -766,13 +819,13 @@ describe "redis" do
766
819
  it 'should yield the correct set elements and scores unchanged' do
767
820
  results = []
768
821
  @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms}
769
- results.should =~ hash_matching_subset.to_a
822
+ expect(results).to match_array(hash_matching_subset.to_a)
770
823
  end
771
824
  end
772
825
  context 'without a block' do
773
826
  it 'should return an Enumerator that yields the correct set elements and scoresunchanged' do
774
827
  enum = @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000)
775
- enum.to_a.should =~ hash_matching_subset.to_a
828
+ expect(enum.to_a).to match_array(hash_matching_subset.to_a)
776
829
  end
777
830
  end
778
831
  end
@@ -781,13 +834,13 @@ describe "redis" do
781
834
  it 'should yield all set elements and scores unchanged' do
782
835
  results = []
783
836
  @namespaced.zscan_each('zset', :count => 1000){ |ms| results << ms }
784
- results.should =~ hash.to_a
837
+ expect(results).to match_array(hash.to_a)
785
838
  end
786
839
  end
787
840
  context 'without a block' do
788
841
  it 'should return an Enumerator that yields all set elements and scores unchanged' do
789
842
  enum = @namespaced.zscan_each('zset', :count => 1000)
790
- enum.to_a.should =~ hash.to_a
843
+ expect(enum.to_a).to match_array(hash.to_a)
791
844
  end
792
845
  end
793
846
  end
@@ -799,12 +852,12 @@ describe "redis" do
799
852
  if @redis_version >= Gem::Version.new("2.8.9")
800
853
  it 'should namespace pfadd' do
801
854
  5.times { |n| @namespaced.pfadd("pf", n) }
802
- @redis.pfcount("ns:pf").should == 5
855
+ expect(@redis.pfcount("ns:pf")).to eq(5)
803
856
  end
804
857
 
805
858
  it 'should namespace pfcount' do
806
859
  5.times { |n| @redis.pfadd("ns:pf", n) }
807
- @namespaced.pfcount("pf").should == 5
860
+ expect(@namespaced.pfcount("pf")).to eq(5)
808
861
  end
809
862
 
810
863
  it 'should namespace pfmerge' do
@@ -814,7 +867,18 @@ describe "redis" do
814
867
  end
815
868
 
816
869
  @namespaced.pfmerge("pfc", "pfa", "pfb")
817
- @redis.pfcount("ns:pfc").should == 10
870
+ expect(@redis.pfcount("ns:pfc")).to eq(10)
871
+ end
872
+ end
873
+
874
+ describe :full_namespace do
875
+ it "should return the full namespace including sub namespaces" do
876
+ sub_namespaced = Redis::Namespace.new(:sub1, :redis => @namespaced)
877
+ sub_sub_namespaced = Redis::Namespace.new(:sub2, :redis => sub_namespaced)
878
+
879
+ expect(@namespaced.full_namespace).to eql("ns")
880
+ expect(sub_namespaced.full_namespace).to eql("ns:sub1")
881
+ expect(sub_sub_namespaced.full_namespace).to eql("ns:sub1:sub2")
818
882
  end
819
883
  end
820
884
  end
@@ -4,6 +4,7 @@ Bundler.setup(:default, :test)
4
4
  Bundler.require(:default, :test)
5
5
 
6
6
  require 'rspec'
7
+ require 'rspec/its'
7
8
  require 'redis'
8
9
  require 'logger'
9
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-namespace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-11-03 00:00:00.000000000 Z
14
+ date: 2019-12-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: redis
@@ -47,14 +47,28 @@ dependencies:
47
47
  requirements:
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: '2.14'
50
+ version: '3.7'
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - "~>"
56
56
  - !ruby/object:Gem::Version
57
- version: '2.14'
57
+ version: '3.7'
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec-its
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
58
72
  description: |
59
73
  Adds a Redis::Namespace class which can be used to namespace calls
60
74
  to Redis. This is useful when using a single instance of Redis with
@@ -87,17 +101,16 @@ require_paths:
87
101
  - lib
88
102
  required_ruby_version: !ruby/object:Gem::Requirement
89
103
  requirements:
90
- - - ">="
104
+ - - "~>"
91
105
  - !ruby/object:Gem::Version
92
- version: '0'
106
+ version: '2.4'
93
107
  required_rubygems_version: !ruby/object:Gem::Requirement
94
108
  requirements:
95
109
  - - ">="
96
110
  - !ruby/object:Gem::Version
97
111
  version: '0'
98
112
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.5.2
113
+ rubygems_version: 3.0.3
101
114
  signing_key:
102
115
  specification_version: 4
103
116
  summary: Namespaces Redis commands.