redis-namespace 1.6.0 → 1.8.1

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: 781a6361b78e31842c9fe934161b83e1acf9d1c1ef50cd015694b78582b461ac
4
+ data.tar.gz: a0856e98fb69b1063c460ef1479dd57a4659741612b398d3fac2d4bb3727e1b0
5
5
  SHA512:
6
- metadata.gz: 4ca1e49aaf2c9e213a0859d1a0bda67f988ddf3a5af08bbf08388a8582298659d6a6869b7d8ee035501d8abf35779be20164dff5b849110f75f173cafb3444e5
7
- data.tar.gz: ca1151681a327f2206370a12f63729ee4f9a0891830274fc0e219353137f09216757421cfb4d4d29c18f73ca2f6e2b7bcf8ff4a0dc55a88324cd0aa7957f2993
6
+ metadata.gz: caf163b05d1f4c5f08a29d4d1f977d666f1a627b582af762f50d883df64f0f2139fe132918edbc6c59d9259f386f7ed7a094da3493579072f25d9c957da7e7eb
7
+ data.tar.gz: 951f20c3aaedd77400f34b161fb642d39ff0a4e8a619506441288f6671043a3bfd3e1f18e13a62fc8e014f79d989246fcb51b351f4d3f1b6f3a2a6ce8f17bd41
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,15 +57,19 @@ 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 ],
66
69
  "del" => [ :all ],
67
70
  "dump" => [ :first ],
68
- "exists" => [ :first ],
71
+ "exists" => [ :all ],
72
+ "exists?" => [ :all ],
69
73
  "expire" => [ :first ],
70
74
  "expireat" => [ :first ],
71
75
  "eval" => [ :eval_style ],
@@ -160,27 +164,31 @@ class Redis
160
164
  "sunionstore" => [ :all ],
161
165
  "ttl" => [ :first ],
162
166
  "type" => [ :first ],
167
+ "unlink" => [ :all ],
163
168
  "unsubscribe" => [ :all ],
164
169
  "zadd" => [ :first ],
165
170
  "zcard" => [ :first ],
166
171
  "zcount" => [ :first ],
167
172
  "zincrby" => [ :first ],
168
173
  "zinterstore" => [ :exclude_options ],
174
+ "zpopmin" => [ :first ],
175
+ "zpopmax" => [ :first ],
169
176
  "zrange" => [ :first ],
170
177
  "zrangebyscore" => [ :first ],
178
+ "zrangebylex" => [ :first ],
171
179
  "zrank" => [ :first ],
172
180
  "zrem" => [ :first ],
173
181
  "zremrangebyrank" => [ :first ],
174
182
  "zremrangebyscore" => [ :first ],
183
+ "zremrangebylex" => [ :first ],
175
184
  "zrevrange" => [ :first ],
176
185
  "zrevrangebyscore" => [ :first ],
186
+ "zrevrangebylex" => [ :first ],
177
187
  "zrevrank" => [ :first ],
178
188
  "zscan" => [ :first ],
179
189
  "zscan_each" => [ :first ],
180
190
  "zscore" => [ :first ],
181
- "zunionstore" => [ :exclude_options ],
182
- "[]" => [ :first ],
183
- "[]=" => [ :first ]
191
+ "zunionstore" => [ :exclude_options ]
184
192
  }
185
193
  TRANSACTION_COMMANDS = {
186
194
  "discard" => [],
@@ -254,7 +262,7 @@ class Redis
254
262
 
255
263
  def client
256
264
  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
265
+ "method instead. Support for the old method will be removed in redis-namespace 2.0.") if @has_new_client_method && deprecations?
258
266
  _client
259
267
  end
260
268
 
@@ -272,7 +280,9 @@ class Redis
272
280
 
273
281
  # emulate Ruby 1.9+ and keep respond_to_missing? logic together.
274
282
  def respond_to?(command, include_private=false)
275
- super or respond_to_missing?(command, include_private)
283
+ return !deprecations? if DEPRECATED_COMMANDS.include?(command.to_s.downcase)
284
+
285
+ respond_to_missing?(command, include_private) or super
276
286
  end
277
287
 
278
288
  def keys(query = nil)
@@ -300,6 +310,14 @@ class Redis
300
310
  @namespace
301
311
  end
302
312
 
313
+ def full_namespace
314
+ redis.is_a?(Namespace) ? "#{redis.full_namespace}:#{namespace}" : namespace.to_s
315
+ end
316
+
317
+ def connection
318
+ @redis.connection.tap { |info| info[:namespace] = @namespace }
319
+ end
320
+
303
321
  def exec
304
322
  call_with_namespace(:exec)
305
323
  end
@@ -307,16 +325,14 @@ class Redis
307
325
  def eval(*args)
308
326
  call_with_namespace(:eval, *args)
309
327
  end
328
+ ruby2_keywords(:eval) if respond_to?(:ruby2_keywords, true)
310
329
 
311
- def method_missing(command, *args, &block)
312
- normalized_command = command.to_s.downcase
330
+ ADMINISTRATIVE_COMMANDS.keys.each do |command|
331
+ define_method(command) do |*args, &block|
332
+ raise NoMethodError if deprecations?
313
333
 
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
334
  if warning?
319
- warn("Passing '#{normalized_command}' command to redis as is; " +
335
+ warn("Passing '#{command}' command to redis as is; " +
320
336
  "administrative commands cannot be effectively namespaced " +
321
337
  "and should be called on the redis connection directly; " +
322
338
  "passthrough has been deprecated and will be removed in " +
@@ -324,8 +340,25 @@ class Redis
324
340
  )
325
341
  end
326
342
  call_with_namespace(command, *args, &block)
327
- elsif COMMANDS.include?(normalized_command)
343
+ end
344
+ ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
345
+ end
346
+
347
+ COMMANDS.keys.each do |command|
348
+ next if ADMINISTRATIVE_COMMANDS.include?(command)
349
+ next if method_defined?(command)
350
+
351
+ define_method(command) do |*args, &block|
328
352
  call_with_namespace(command, *args, &block)
353
+ end
354
+ ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
355
+ end
356
+
357
+ def method_missing(command, *args, &block)
358
+ normalized_command = command.to_s.downcase
359
+
360
+ if COMMANDS.include?(normalized_command)
361
+ send(normalized_command, *args, &block)
329
362
  elsif @redis.respond_to?(normalized_command) && !deprecations?
330
363
  # blind passthrough is deprecated and will be removed in 2.0
331
364
  # redis-namespace does not know how to handle this command.
@@ -341,18 +374,17 @@ class Redis
341
374
  super
342
375
  end
343
376
  end
377
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
344
378
 
345
379
  def inspect
346
380
  "<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\
347
- "for #{@redis.id}/#{@namespace}>"
381
+ "for #{@redis.id}/#{full_namespace}>"
348
382
  end
349
383
 
350
384
  def respond_to_missing?(command, include_all=false)
351
385
  normalized_command = command.to_s.downcase
352
386
 
353
387
  case
354
- when DEPRECATED_COMMANDS.include?(normalized_command)
355
- !deprecations?
356
388
  when COMMANDS.include?(normalized_command)
357
389
  true
358
390
  when !deprecations? && redis.respond_to?(command, include_all)
@@ -378,6 +410,7 @@ class Redis
378
410
  case before
379
411
  when :first
380
412
  args[0] = add_namespace(args[0]) if args[0]
413
+ args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash)
381
414
  when :all
382
415
  args = add_namespace(args)
383
416
  when :exclude_first
@@ -390,7 +423,7 @@ class Redis
390
423
  args.push(last) if last
391
424
  when :exclude_options
392
425
  if args.last.is_a?(Hash)
393
- last = args.pop
426
+ last = ruby2_keywords_hash(args.pop)
394
427
  args = add_namespace(args)
395
428
  args.push(last)
396
429
  else
@@ -410,6 +443,7 @@ class Redis
410
443
  args[1][:get].each_index do |i|
411
444
  args[1][:get][i] = add_namespace(args[1][:get][i]) unless args[1][:get][i] == "#"
412
445
  end
446
+ args[1] = ruby2_keywords_hash(args[1])
413
447
  end
414
448
  when :eval_style
415
449
  # redis.eval() and evalsha() can either take the form:
@@ -430,7 +464,7 @@ class Redis
430
464
  when :scan_style
431
465
  options = (args.last.kind_of?(Hash) ? args.pop : {})
432
466
  options[:match] = add_namespace(options.fetch(:match, '*'))
433
- args << options
467
+ args << ruby2_keywords_hash(options)
434
468
 
435
469
  if block
436
470
  original_block = block
@@ -456,9 +490,20 @@ class Redis
456
490
 
457
491
  result
458
492
  end
493
+ ruby2_keywords(:call_with_namespace) if respond_to?(:ruby2_keywords, true)
459
494
 
460
495
  private
461
496
 
497
+ if Hash.respond_to?(:ruby2_keywords_hash)
498
+ def ruby2_keywords_hash(kwargs)
499
+ Hash.ruby2_keywords_hash(kwargs)
500
+ end
501
+ else
502
+ def ruby2_keywords_hash(kwargs)
503
+ kwargs
504
+ end
505
+ end
506
+
462
507
  # Avoid modifying the caller's (pass-by-reference) arguments.
463
508
  def clone_args(arg)
464
509
  if arg.is_a?(Array)
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Redis
4
4
  class Namespace
5
- VERSION = '1.6.0'
5
+ VERSION = '1.8.1'
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 }
data/spec/redis_spec.rb CHANGED
@@ -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,154 @@ 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 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)
128
163
  end
129
164
 
130
165
  it 'should be able to use a namespace with setrange' do
131
166
  @namespaced.setrange('foo', 0, 'bar')
132
- @namespaced.get('foo').should eq('bar')
167
+ expect(@namespaced.get('foo')).to eq('bar')
133
168
 
134
169
  @namespaced.setrange('bar', 2, 'foo')
135
- @namespaced.get('bar').should eq("\000\000foo")
170
+ expect(@namespaced.get('bar')).to eq("\000\000foo")
136
171
  end
137
172
 
138
173
  it "should be able to use a namespace with mget" do
139
174
  @namespaced.set('foo', 1000)
140
175
  @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})
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})
143
178
  end
144
179
 
145
180
  it "should be able to use a namespace with mset" do
146
181
  @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})
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})
149
184
  @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})
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})
152
187
  end
153
188
 
154
189
  it "should be able to use a namespace with msetnx" do
155
190
  @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})
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})
158
193
  end
159
194
 
160
195
  it "should be able to use a namespace with mapped_msetnx" do
161
196
  @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' })
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' })
166
201
  end
167
202
 
168
203
  it "should be able to use a namespace with hashes" do
169
204
  @namespaced.hset('foo', 'key', 'value')
170
205
  @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'])
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'])
175
210
  @namespaced.hmset('bar', 'key', 'value', 'key1', 'value1')
176
211
  @namespaced.hmget('bar', 'key', 'key1')
177
212
  @namespaced.hmset('bar', 'a_number', 1)
178
- @namespaced.hmget('bar', 'a_number').should eq(['1'])
213
+ expect(@namespaced.hmget('bar', 'a_number')).to eq(['1'])
179
214
  @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 })
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 })
188
223
  @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'})
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'})
191
226
  end
192
227
 
193
228
  it "should properly intersect three sets" do
@@ -198,7 +233,7 @@ describe "redis" do
198
233
  @namespaced.sadd('bar', 3)
199
234
  @namespaced.sadd('bar', 4)
200
235
  @namespaced.sadd('baz', 3)
201
- @namespaced.sinter('foo', 'bar', 'baz').should eq(%w( 3 ))
236
+ expect(@namespaced.sinter('foo', 'bar', 'baz')).to eq(%w( 3 ))
202
237
  end
203
238
 
204
239
  it "should properly union two sets" do
@@ -207,7 +242,7 @@ describe "redis" do
207
242
  @namespaced.sadd('bar', 2)
208
243
  @namespaced.sadd('bar', 3)
209
244
  @namespaced.sadd('bar', 4)
210
- @namespaced.sunion('foo', 'bar').sort.should eq(%w( 1 2 3 4 ))
245
+ expect(@namespaced.sunion('foo', 'bar').sort).to eq(%w( 1 2 3 4 ))
211
246
  end
212
247
 
213
248
  it "should properly union two sorted sets with options" do
@@ -216,8 +251,8 @@ describe "redis" do
216
251
  @namespaced.zadd('sort2', 2, 2)
217
252
  @namespaced.zadd('sort2', 3, 3)
218
253
  @namespaced.zadd('sort2', 4, 4)
219
- @namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1])
220
- @namespaced.zrevrange('union', 0, -1).should eq(%w( 2 4 3 1 ))
254
+ @namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1])
255
+ expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
221
256
  end
222
257
 
223
258
  it "should properly union two sorted sets without options" do
@@ -227,7 +262,7 @@ describe "redis" do
227
262
  @namespaced.zadd('sort2', 3, 3)
228
263
  @namespaced.zadd('sort2', 4, 4)
229
264
  @namespaced.zunionstore('union', ['sort1', 'sort2'])
230
- @namespaced.zrevrange('union', 0, -1).should eq(%w( 4 2 3 1 ))
265
+ expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 4 2 3 1 ))
231
266
  end
232
267
 
233
268
  it "should properly intersect two sorted sets without options" do
@@ -242,7 +277,7 @@ describe "redis" do
242
277
  @namespaced.zinterstore('inter', ['food', 'color'])
243
278
 
244
279
  inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
245
- inter_values.should =~ [['orange', 3.0], ['eggplant', 7.0]]
280
+ expect(inter_values).to match_array([['orange', 3.0], ['eggplant', 7.0]])
246
281
  end
247
282
 
248
283
  it "should properly intersect two sorted sets with options" do
@@ -257,7 +292,37 @@ describe "redis" do
257
292
  @namespaced.zinterstore('inter', ['food', 'color'], :aggregate => "min")
258
293
 
259
294
  inter_values = @namespaced.zrevrange('inter', 0, -1, :with_scores => true)
260
- inter_values.should =~ [['orange', 1.0], ['eggplant', 3.0]]
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'])
261
326
  end
262
327
 
263
328
  it "should add namespace to sort" do
@@ -268,24 +333,24 @@ describe "redis" do
268
333
  @namespaced.set('value_1', 'a')
269
334
  @namespaced.set('value_2', 'b')
270
335
 
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"]])
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"]])
278
343
 
279
344
  @namespaced.sort('foo', :store => 'result')
280
- @namespaced.lrange('result', 0, -1).should eq(%w( 1 2 ))
345
+ expect(@namespaced.lrange('result', 0, -1)).to eq(%w( 1 2 ))
281
346
  end
282
347
 
283
348
  it "should yield the correct list of keys" do
284
349
  @namespaced.set("foo", 1)
285
350
  @namespaced.set("bar", 2)
286
351
  @namespaced.set("baz", 3)
287
- @namespaced.keys("*").sort.should eq(%w( bar baz foo ))
288
- @namespaced.keys.sort.should eq(%w( bar baz foo ))
352
+ expect(@namespaced.keys("*").sort).to eq(%w( bar baz foo ))
353
+ expect(@namespaced.keys.sort).to eq(%w( bar baz foo ))
289
354
  end
290
355
 
291
356
  it "should add namepsace to multi blocks" do
@@ -294,7 +359,7 @@ describe "redis" do
294
359
  r.del "foo"
295
360
  r.mapped_hmset "foo", {"key1" => "value1"}
296
361
  end
297
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
362
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
298
363
  end
299
364
 
300
365
  it "should pass through multi commands without block" do
@@ -305,14 +370,14 @@ describe "redis" do
305
370
  @namespaced.mapped_hmset "foo", {"key1" => "value1"}
306
371
  @namespaced.exec
307
372
 
308
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
373
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
309
374
  end
310
375
 
311
376
  it 'should return futures without attempting to remove namespaces' do
312
377
  @namespaced.multi do
313
378
  @future = @namespaced.keys('*')
314
379
  end
315
- @future.class.should be(Redis::Future)
380
+ expect(@future.class).to be(Redis::Future)
316
381
  end
317
382
 
318
383
  it "should add namespace to pipelined blocks" do
@@ -321,7 +386,7 @@ describe "redis" do
321
386
  r.del "foo"
322
387
  r.mapped_hmset "foo", {"key1" => "value1"}
323
388
  end
324
- @namespaced.hgetall("foo").should eq({"key1" => "value1"})
389
+ expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
325
390
  end
326
391
 
327
392
  it "should returned response array from pipelined block" do
@@ -330,65 +395,104 @@ describe "redis" do
330
395
  r.get("foo")
331
396
  r.get("key")
332
397
  end
333
- result.should eq(["bar", "value"])
398
+ expect(result).to eq(["bar", "value"])
334
399
  end
335
400
 
336
401
  it "should add namespace to strlen" do
337
402
  @namespaced.set("mykey", "123456")
338
- @namespaced.strlen("mykey").should eq(6)
403
+ expect(@namespaced.strlen("mykey")).to eq(6)
339
404
  end
340
405
 
341
406
  it "should not add namespace to echo" do
342
- @namespaced.echo(123).should eq("123")
407
+ expect(@namespaced.echo(123)).to eq("123")
343
408
  end
344
409
 
345
410
  it 'should not add namespace to disconnect!' do
346
- expect(@redis).to receive(:disconnect!).with().and_call_original
411
+ expect(@redis).to receive(:disconnect!).with(no_args).and_call_original
347
412
 
348
413
  expect(@namespaced.disconnect!).to be nil
349
414
  end
350
415
 
351
416
  it "can change its namespace" do
352
- @namespaced.get('foo').should eq(nil)
417
+ expect(@namespaced.get('foo')).to eq(nil)
353
418
  @namespaced.set('foo', 'chris')
354
- @namespaced.get('foo').should eq('chris')
419
+ expect(@namespaced.get('foo')).to eq('chris')
355
420
 
356
- @namespaced.namespace.should eq(:ns)
421
+ expect(@namespaced.namespace).to eq(:ns)
357
422
  @namespaced.namespace = :spec
358
- @namespaced.namespace.should eq(:spec)
423
+ expect(@namespaced.namespace).to eq(:spec)
359
424
 
360
- @namespaced.get('foo').should eq(nil)
425
+ expect(@namespaced.get('foo')).to eq(nil)
361
426
  @namespaced.set('foo', 'chris')
362
- @namespaced.get('foo').should eq('chris')
427
+ expect(@namespaced.get('foo')).to eq('chris')
363
428
  end
364
429
 
365
430
  it "can accept a temporary namespace" do
366
- @namespaced.namespace.should eq(:ns)
367
- @namespaced.get('foo').should eq(nil)
431
+ expect(@namespaced.namespace).to eq(:ns)
432
+ expect(@namespaced.get('foo')).to eq(nil)
368
433
 
369
434
  @namespaced.namespace(:spec) do |temp_ns|
370
- temp_ns.namespace.should eq(:spec)
371
- temp_ns.get('foo').should eq(nil)
435
+ expect(temp_ns.namespace).to eq(:spec)
436
+ expect(temp_ns.get('foo')).to eq(nil)
372
437
  temp_ns.set('foo', 'jake')
373
- temp_ns.get('foo').should eq('jake')
438
+ expect(temp_ns.get('foo')).to eq('jake')
374
439
  end
375
440
 
376
- @namespaced.namespace.should eq(:ns)
377
- @namespaced.get('foo').should eq(nil)
441
+ expect(@namespaced.namespace).to eq(:ns)
442
+ expect(@namespaced.get('foo')).to eq(nil)
378
443
  end
379
444
 
380
445
  it "should respond to :namespace=" do
381
- @namespaced.respond_to?(:namespace=).should eq(true)
446
+ expect(@namespaced.respond_to?(:namespace=)).to eq(true)
382
447
  end
383
448
 
384
449
  it "should respond to :warning=" do
385
- @namespaced.respond_to?(:warning=).should == true
450
+ expect(@namespaced.respond_to?(:warning=)).to eq(true)
386
451
  end
387
452
 
388
453
  it "should raise an exception when an unknown command is passed" do
389
454
  expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
390
455
  end
391
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
+
392
496
  # Redis 2.6 RC reports its version as 2.5.
393
497
  if @redis_version >= Gem::Version.new("2.5.0")
394
498
  describe "redis 2.6 commands" do
@@ -422,7 +526,7 @@ describe "redis" do
422
526
  v = @namespaced.dump("foo")
423
527
  @redis.del("ns:foo")
424
528
 
425
- expect(@namespaced.restore("foo", 1000, v)).to be_true
529
+ expect(@namespaced.restore("foo", 1000, v)).to be_truthy
426
530
  expect(@redis.get("ns:foo")).to eq 'a'
427
531
  expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
428
532
 
@@ -430,72 +534,72 @@ describe "redis" do
430
534
  w = @namespaced.dump("bar")
431
535
  @redis.del("ns:bar")
432
536
 
433
- expect(@namespaced.restore("bar", 1000, w)).to be_true
537
+ expect(@namespaced.restore("bar", 1000, w)).to be_truthy
434
538
  expect(@redis.lrange('ns:bar', 0, -1)).to eq %w(b c d)
435
539
  expect(@redis.ttl("ns:foo")).to satisfy {|v| (0..1).include?(v) }
436
540
  end
437
541
 
438
542
  it "should namespace hincrbyfloat" do
439
543
  @namespaced.hset('mykey', 'field', 10.50)
440
- @namespaced.hincrbyfloat('mykey', 'field', 0.1).should eq(10.6)
544
+ expect(@namespaced.hincrbyfloat('mykey', 'field', 0.1)).to eq(10.6)
441
545
  end
442
546
 
443
547
  it "should namespace incrbyfloat" do
444
548
  @namespaced.set('mykey', 10.50)
445
- @namespaced.incrbyfloat('mykey', 0.1).should eq(10.6)
549
+ expect(@namespaced.incrbyfloat('mykey', 0.1)).to eq(10.6)
446
550
  end
447
551
 
448
552
  it "should namespace object" do
449
553
  @namespaced.set('foo', 1000)
450
- @namespaced.object('encoding', 'foo').should eq('int')
554
+ expect(@namespaced.object('encoding', 'foo')).to eq('int')
451
555
  end
452
556
 
453
557
  it "should namespace persist" do
454
558
  @namespaced.set('mykey', 'Hello')
455
559
  @namespaced.expire('mykey', 60)
456
- @namespaced.persist('mykey').should eq(true)
457
- @namespaced.ttl('mykey').should eq(-1)
560
+ expect(@namespaced.persist('mykey')).to eq(true)
561
+ expect(@namespaced.ttl('mykey')).to eq(-1)
458
562
  end
459
563
 
460
564
  it "should namespace pexpire" do
461
565
  @namespaced.set('mykey', 'Hello')
462
- @namespaced.pexpire('mykey', 60000).should eq(true)
566
+ expect(@namespaced.pexpire('mykey', 60000)).to eq(true)
463
567
  end
464
568
 
465
569
  it "should namespace pexpireat" do
466
570
  @namespaced.set('mykey', 'Hello')
467
- @namespaced.pexpire('mykey', 1555555555005).should eq(true)
571
+ expect(@namespaced.pexpire('mykey', 1555555555005)).to eq(true)
468
572
  end
469
573
 
470
574
  it "should namespace psetex" do
471
- @namespaced.psetex('mykey', 10000, 'Hello').should eq('OK')
472
- @namespaced.get('mykey').should eq('Hello')
575
+ expect(@namespaced.psetex('mykey', 10000, 'Hello')).to eq('OK')
576
+ expect(@namespaced.get('mykey')).to eq('Hello')
473
577
  end
474
578
 
475
579
  it "should namespace pttl" do
476
580
  @namespaced.set('mykey', 'Hello')
477
581
  @namespaced.expire('mykey', 1)
478
- @namespaced.pttl('mykey').should >= 0
582
+ expect(@namespaced.pttl('mykey')).to be >= 0
479
583
  end
480
584
 
481
585
  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])
586
+ expect(@namespaced.
587
+ eval("return {KEYS[1], KEYS[2]}", %w[k1 k2], %w[arg1 arg2])).
588
+ to eq(%w[ns:k1 ns:k2])
485
589
  end
486
590
 
487
591
  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])
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])
491
595
  end
492
596
 
493
597
  it "should namespace eval keys passed in as hash args unmodified" do
494
598
  args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
495
599
  args.freeze
496
- @namespaced.
497
- eval("return {KEYS[1], KEYS[2]}", args).
498
- should eq(%w[ns:k1 ns:k2])
600
+ expect(@namespaced.
601
+ eval("return {KEYS[1], KEYS[2]}", args)).
602
+ to eq(%w[ns:k1 ns:k2])
499
603
  end
500
604
 
501
605
  context '#evalsha' do
@@ -504,23 +608,23 @@ describe "redis" do
504
608
  end
505
609
 
506
610
  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])
611
+ expect(@namespaced.
612
+ evalsha(sha, %w[k1 k2], %w[arg1 arg2])).
613
+ to eq(%w[ns:k1 ns:k2])
510
614
  end
511
615
 
512
616
  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])
617
+ expect(@namespaced.
618
+ evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
619
+ to eq(%w[ns:k1 ns:k2])
516
620
  end
517
621
 
518
622
  it "should namespace evalsha keys passed in as hash args unmodified" do
519
623
  args = { :keys => %w[k1 k2], :argv => %w[arg1 arg2] }
520
624
  args.freeze
521
- @namespaced.
522
- evalsha(sha, args).
523
- should eq(%w[ns:k1 ns:k2])
625
+ expect(@namespaced.
626
+ evalsha(sha, args)).
627
+ to eq(%w[ns:k1 ns:k2])
524
628
  end
525
629
  end
526
630
 
@@ -529,13 +633,13 @@ describe "redis" do
529
633
  let(:sha) { @redis.script(:load, "return {KEYS[1], KEYS[2]}") }
530
634
 
531
635
  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])
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])
535
639
  end
536
640
  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])
641
+ expect(nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2])).
642
+ to eq(%w[ns:nest:k1 ns:nest:k2])
539
643
  end
540
644
  end
541
645
  end
@@ -564,13 +668,13 @@ describe "redis" do
564
668
  context 'when :match supplied' do
565
669
  it 'should retrieve the proper keys' do
566
670
  _, result = @namespaced.scan(0, :match => 'zeta:*', :count => 1000)
567
- result.should =~ matching_namespaced_keys
671
+ expect(result).to match_array(matching_namespaced_keys)
568
672
  end
569
673
  end
570
674
  context 'without :match supplied' do
571
675
  it 'should retrieve the proper keys' do
572
676
  _, result = @namespaced.scan(0, :count => 1000)
573
- result.should =~ namespaced_keys
677
+ expect(result).to match_array(namespaced_keys)
574
678
  end
575
679
  end
576
680
  end if Redis.current.respond_to?(:scan)
@@ -581,13 +685,13 @@ describe "redis" do
581
685
  it 'should yield unnamespaced' do
582
686
  results = []
583
687
  @namespaced.scan_each(:match => 'zeta:*', :count => 1000) {|k| results << k }
584
- results.should =~ matching_namespaced_keys
688
+ expect(results).to match_array(matching_namespaced_keys)
585
689
  end
586
690
  end
587
691
  context 'without a block' do
588
692
  it 'should return an Enumerator that un-namespaces' do
589
693
  enum = @namespaced.scan_each(:match => 'zeta:*', :count => 1000)
590
- enum.to_a.should =~ matching_namespaced_keys
694
+ expect(enum.to_a).to match_array(matching_namespaced_keys)
591
695
  end
592
696
  end
593
697
  end
@@ -596,13 +700,13 @@ describe "redis" do
596
700
  it 'should yield unnamespaced' do
597
701
  results = []
598
702
  @namespaced.scan_each(:count => 1000){ |k| results << k }
599
- results.should =~ namespaced_keys
703
+ expect(results).to match_array(namespaced_keys)
600
704
  end
601
705
  end
602
706
  context 'without a block' do
603
707
  it 'should return an Enumerator that un-namespaces' do
604
708
  enum = @namespaced.scan_each(:count => 1000)
605
- enum.to_a.should =~ namespaced_keys
709
+ expect(enum.to_a).to match_array(namespaced_keys)
606
710
  end
607
711
  end
608
712
  end
@@ -625,13 +729,13 @@ describe "redis" do
625
729
  context 'when supplied :match' do
626
730
  it 'should retrieve the proper keys' do
627
731
  _, results = @namespaced.hscan('hsh', 0, :match => 'zeta:*')
628
- results.should =~ hash_matching_subset.to_a
732
+ expect(results).to match_array(hash_matching_subset.to_a)
629
733
  end
630
734
  end
631
735
  context 'without :match supplied' do
632
736
  it 'should retrieve all hash keys' do
633
737
  _, results = @namespaced.hscan('hsh', 0)
634
- results.should =~ @redis.hgetall('ns:hsh').to_a
738
+ expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
635
739
  end
636
740
  end
637
741
  end if Redis.current.respond_to?(:hscan)
@@ -642,13 +746,13 @@ describe "redis" do
642
746
  it 'should yield the correct hash keys unchanged' do
643
747
  results = []
644
748
  @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
645
- results.should =~ hash_matching_subset.to_a
749
+ expect(results).to match_array(hash_matching_subset.to_a)
646
750
  end
647
751
  end
648
752
  context 'without a block' do
649
753
  it 'should return an Enumerator that yields the correct hash keys unchanged' do
650
754
  enum = @namespaced.hscan_each('hsh', :match => 'zeta:*', :count => 1000)
651
- enum.to_a.should =~ hash_matching_subset.to_a
755
+ expect(enum.to_a).to match_array(hash_matching_subset.to_a)
652
756
  end
653
757
  end
654
758
  end
@@ -657,13 +761,13 @@ describe "redis" do
657
761
  it 'should yield all hash keys unchanged' do
658
762
  results = []
659
763
  @namespaced.hscan_each('hsh', :count => 1000){ |k| results << k }
660
- results.should =~ hash.to_a
764
+ expect(results).to match_array(hash.to_a)
661
765
  end
662
766
  end
663
767
  context 'without a block' do
664
768
  it 'should return an Enumerator that yields all keys unchanged' do
665
769
  enum = @namespaced.hscan_each('hsh', :count => 1000)
666
- enum.to_a.should =~ hash.to_a
770
+ expect(enum.to_a).to match_array(hash.to_a)
667
771
  end
668
772
  end
669
773
  end
@@ -686,13 +790,13 @@ describe "redis" do
686
790
  context 'when supplied :match' do
687
791
  it 'should retrieve the matching set members from the proper set' do
688
792
  _, results = @namespaced.sscan('set', 0, :match => 'zeta:*', :count => 1000)
689
- results.should =~ matching_subset
793
+ expect(results).to match_array(matching_subset)
690
794
  end
691
795
  end
692
796
  context 'without :match supplied' do
693
797
  it 'should retrieve all set members from the proper set' do
694
798
  _, results = @namespaced.sscan('set', 0, :count => 1000)
695
- results.should =~ set
799
+ expect(results).to match_array(set)
696
800
  end
697
801
  end
698
802
  end if Redis.current.respond_to?(:sscan)
@@ -703,13 +807,13 @@ describe "redis" do
703
807
  it 'should yield the correct hset elements unchanged' do
704
808
  results = []
705
809
  @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000) { |kv| results << kv}
706
- results.should =~ matching_subset
810
+ expect(results).to match_array(matching_subset)
707
811
  end
708
812
  end
709
813
  context 'without a block' do
710
814
  it 'should return an Enumerator that yields the correct set elements unchanged' do
711
815
  enum = @namespaced.sscan_each('set', :match => 'zeta:*', :count => 1000)
712
- enum.to_a.should =~ matching_subset
816
+ expect(enum.to_a).to match_array(matching_subset)
713
817
  end
714
818
  end
715
819
  end
@@ -718,13 +822,13 @@ describe "redis" do
718
822
  it 'should yield all set elements unchanged' do
719
823
  results = []
720
824
  @namespaced.sscan_each('set', :count => 1000){ |k| results << k }
721
- results.should =~ set
825
+ expect(results).to match_array(set)
722
826
  end
723
827
  end
724
828
  context 'without a block' do
725
829
  it 'should return an Enumerator that yields all set elements unchanged' do
726
830
  enum = @namespaced.sscan_each('set', :count => 1000)
727
- enum.to_a.should =~ set
831
+ expect(enum.to_a).to match_array(set)
728
832
  end
729
833
  end
730
834
  end
@@ -748,14 +852,14 @@ describe "redis" do
748
852
  it 'should retrieve the matching set elements and their scores' do
749
853
  results = []
750
854
  @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms }
751
- results.should =~ hash_matching_subset.to_a
855
+ expect(results).to match_array(hash_matching_subset.to_a)
752
856
  end
753
857
  end
754
858
  context 'without :match supplied' do
755
859
  it 'should retrieve all set elements and their scores' do
756
860
  results = []
757
861
  @namespaced.zscan_each('zset', :count => 1000) { |ms| results << ms }
758
- results.should =~ hash.to_a
862
+ expect(results).to match_array(hash.to_a)
759
863
  end
760
864
  end
761
865
  end if Redis.current.respond_to?(:zscan)
@@ -766,13 +870,13 @@ describe "redis" do
766
870
  it 'should yield the correct set elements and scores unchanged' do
767
871
  results = []
768
872
  @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000) { |ms| results << ms}
769
- results.should =~ hash_matching_subset.to_a
873
+ expect(results).to match_array(hash_matching_subset.to_a)
770
874
  end
771
875
  end
772
876
  context 'without a block' do
773
877
  it 'should return an Enumerator that yields the correct set elements and scoresunchanged' do
774
878
  enum = @namespaced.zscan_each('zset', :match => 'zeta:*', :count => 1000)
775
- enum.to_a.should =~ hash_matching_subset.to_a
879
+ expect(enum.to_a).to match_array(hash_matching_subset.to_a)
776
880
  end
777
881
  end
778
882
  end
@@ -781,13 +885,13 @@ describe "redis" do
781
885
  it 'should yield all set elements and scores unchanged' do
782
886
  results = []
783
887
  @namespaced.zscan_each('zset', :count => 1000){ |ms| results << ms }
784
- results.should =~ hash.to_a
888
+ expect(results).to match_array(hash.to_a)
785
889
  end
786
890
  end
787
891
  context 'without a block' do
788
892
  it 'should return an Enumerator that yields all set elements and scores unchanged' do
789
893
  enum = @namespaced.zscan_each('zset', :count => 1000)
790
- enum.to_a.should =~ hash.to_a
894
+ expect(enum.to_a).to match_array(hash.to_a)
791
895
  end
792
896
  end
793
897
  end
@@ -799,12 +903,12 @@ describe "redis" do
799
903
  if @redis_version >= Gem::Version.new("2.8.9")
800
904
  it 'should namespace pfadd' do
801
905
  5.times { |n| @namespaced.pfadd("pf", n) }
802
- @redis.pfcount("ns:pf").should == 5
906
+ expect(@redis.pfcount("ns:pf")).to eq(5)
803
907
  end
804
908
 
805
909
  it 'should namespace pfcount' do
806
910
  5.times { |n| @redis.pfadd("ns:pf", n) }
807
- @namespaced.pfcount("pf").should == 5
911
+ expect(@namespaced.pfcount("pf")).to eq(5)
808
912
  end
809
913
 
810
914
  it 'should namespace pfmerge' do
@@ -814,7 +918,18 @@ describe "redis" do
814
918
  end
815
919
 
816
920
  @namespaced.pfmerge("pfc", "pfa", "pfb")
817
- @redis.pfcount("ns:pfc").should == 10
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")
818
933
  end
819
934
  end
820
935
  end