redis-namespace 1.7.0 → 1.8.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
2
  SHA256:
3
- metadata.gz: 9ebbb9000d7b34a0a8386ac9d72e2f63f4573720b22a8eb7e3676c0c1759200b
4
- data.tar.gz: ec5c495b22e58cc98d4c759f7873f2d2f9f69c8205b750062207b6f4b1f45897
3
+ metadata.gz: 07470c91421a4a15227f10daff0378fdd85a7ba7abc30357677cca67ca87305f
4
+ data.tar.gz: 50e2b6ff0b1db22abe4bbfd77e486d9fd71c09122ba3c01bbfbf90710d21353d
5
5
  SHA512:
6
- metadata.gz: e05aa113c14df634a64fdfad7891781ace6a5060a533e9417f94476235f3e05fd33859c4653fcbe8f417582e9257cdf20b1599ac1b2e4cbe38ccaf7c88af2dba
7
- data.tar.gz: 220e3ec476e5613dd3a8529f2f7b30f7aba9433a1f4ab4402c55be555ef00ff5651738824ddc583e83e7cbad9297d1f1a107bd61e4b44df5e8c9efa50589cfea
6
+ metadata.gz: ec82e340922480f5a48a8bba472babc3385abc84104b56d13f9e94a2654c5a4aaef1d38f1c2a11535a8f5c5ca02aed3ab1c157fb983b7251458f6b8547b08710
7
+ data.tar.gz: 129b38893696d94b57aa04d07fe399e59d76fd6b4269531c7dbee9334604041b9a1fca931ff7a4a8e16dee9b57f9756e26a6cf1b3d9f989139dbcd31f6d5b0ce
@@ -68,7 +68,8 @@ class Redis
68
68
  "decrby" => [ :first ],
69
69
  "del" => [ :all ],
70
70
  "dump" => [ :first ],
71
- "exists" => [ :first ],
71
+ "exists" => [ :all ],
72
+ "exists?" => [ :all ],
72
73
  "expire" => [ :first ],
73
74
  "expireat" => [ :first ],
74
75
  "eval" => [ :eval_style ],
@@ -324,6 +325,7 @@ class Redis
324
325
  def eval(*args)
325
326
  call_with_namespace(:eval, *args)
326
327
  end
328
+ ruby2_keywords(:eval) if respond_to?(:ruby2_keywords, true)
327
329
 
328
330
  ADMINISTRATIVE_COMMANDS.keys.each do |command|
329
331
  define_method(command) do |*args, &block|
@@ -339,6 +341,7 @@ class Redis
339
341
  end
340
342
  call_with_namespace(command, *args, &block)
341
343
  end
344
+ ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
342
345
  end
343
346
 
344
347
  COMMANDS.keys.each do |command|
@@ -348,6 +351,7 @@ class Redis
348
351
  define_method(command) do |*args, &block|
349
352
  call_with_namespace(command, *args, &block)
350
353
  end
354
+ ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
351
355
  end
352
356
 
353
357
  def method_missing(command, *args, &block)
@@ -370,10 +374,11 @@ class Redis
370
374
  super
371
375
  end
372
376
  end
377
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
373
378
 
374
379
  def inspect
375
380
  "<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\
376
- "for #{@redis.id}/#{@namespace}>"
381
+ "for #{@redis.id}/#{full_namespace}>"
377
382
  end
378
383
 
379
384
  def respond_to_missing?(command, include_all=false)
@@ -405,6 +410,7 @@ class Redis
405
410
  case before
406
411
  when :first
407
412
  args[0] = add_namespace(args[0]) if args[0]
413
+ args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash)
408
414
  when :all
409
415
  args = add_namespace(args)
410
416
  when :exclude_first
@@ -417,7 +423,7 @@ class Redis
417
423
  args.push(last) if last
418
424
  when :exclude_options
419
425
  if args.last.is_a?(Hash)
420
- last = args.pop
426
+ last = ruby2_keywords_hash(args.pop)
421
427
  args = add_namespace(args)
422
428
  args.push(last)
423
429
  else
@@ -437,6 +443,7 @@ class Redis
437
443
  args[1][:get].each_index do |i|
438
444
  args[1][:get][i] = add_namespace(args[1][:get][i]) unless args[1][:get][i] == "#"
439
445
  end
446
+ args[1] = ruby2_keywords_hash(args[1])
440
447
  end
441
448
  when :eval_style
442
449
  # redis.eval() and evalsha() can either take the form:
@@ -457,7 +464,7 @@ class Redis
457
464
  when :scan_style
458
465
  options = (args.last.kind_of?(Hash) ? args.pop : {})
459
466
  options[:match] = add_namespace(options.fetch(:match, '*'))
460
- args << options
467
+ args << ruby2_keywords_hash(options)
461
468
 
462
469
  if block
463
470
  original_block = block
@@ -483,9 +490,20 @@ class Redis
483
490
 
484
491
  result
485
492
  end
493
+ ruby2_keywords(:call_with_namespace) if respond_to?(:ruby2_keywords, true)
486
494
 
487
495
  private
488
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
+
489
507
  # Avoid modifying the caller's (pass-by-reference) arguments.
490
508
  def clone_args(arg)
491
509
  if arg.is_a?(Array)
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Redis
4
4
  class Namespace
5
- VERSION = '1.7.0'
5
+ VERSION = '1.8.0'
6
6
  end
7
7
  end
@@ -140,10 +140,22 @@ describe "redis" do
140
140
 
141
141
  it 'should be able to use a namespace with setbit' do
142
142
  @namespaced.setbit('virgin_key', 1, 1)
143
- expect(@namespaced.exists('virgin_key')).to be true
143
+ expect(@namespaced.exists?('virgin_key')).to be true
144
144
  expect(@namespaced.get('virgin_key')).to eq(@namespaced.getrange('virgin_key',0,-1))
145
145
  end
146
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
+
147
159
  it 'should be able to use a namespace with bitpos' do
148
160
  @namespaced.setbit('bit_map', 42, 1)
149
161
  expect(@namespaced.bitpos('bit_map', 0)).to eq(0)
@@ -239,7 +251,7 @@ describe "redis" do
239
251
  @namespaced.zadd('sort2', 2, 2)
240
252
  @namespaced.zadd('sort2', 3, 3)
241
253
  @namespaced.zadd('sort2', 4, 4)
242
- @namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1])
254
+ @namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1])
243
255
  expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
244
256
  end
245
257
 
@@ -442,6 +454,45 @@ describe "redis" do
442
454
  expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
443
455
  end
444
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
+
445
496
  # Redis 2.6 RC reports its version as 2.5.
446
497
  if @redis_version >= Gem::Version.new("2.5.0")
447
498
  describe "redis 2.6 commands" do
@@ -12,6 +12,10 @@ $TESTING=true
12
12
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
13
  require 'redis/namespace'
14
14
 
15
+ if Redis.respond_to?(:exists_returns_integer=)
16
+ Redis.exists_returns_integer = true
17
+ end
18
+
15
19
  module Helper
16
20
  def capture_stderr(io = nil)
17
21
  require 'stringio'
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.7.0
4
+ version: 1.8.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: 2019-12-11 00:00:00.000000000 Z
14
+ date: 2020-08-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: redis
@@ -31,16 +31,16 @@ dependencies:
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - "~>"
34
+ - - ">="
35
35
  - !ruby/object:Gem::Version
36
- version: '10.1'
36
+ version: '0'
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "~>"
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '10.1'
43
+ version: '0'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: rspec
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -91,10 +91,14 @@ files:
91
91
  - spec/deprecation_spec.rb
92
92
  - spec/redis_spec.rb
93
93
  - spec/spec_helper.rb
94
- homepage: http://github.com/resque/redis-namespace
94
+ homepage: https://github.com/resque/redis-namespace
95
95
  licenses:
96
96
  - MIT
97
- metadata: {}
97
+ metadata:
98
+ bug_tracker_uri: https://github.com/resque/redis-namespace/issues
99
+ changelog_uri: https://github.com/resque/redis-namespace/blob/master/CHANGELOG.md
100
+ documentation_uri: https://www.rubydoc.info/gems/redis-namespace/1.8.0
101
+ source_code_uri: https://github.com/resque/redis-namespace/tree/v1.8.0
98
102
  post_install_message:
99
103
  rdoc_options: []
100
104
  require_paths:
@@ -110,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
114
  - !ruby/object:Gem::Version
111
115
  version: '0'
112
116
  requirements: []
113
- rubygems_version: 3.0.3
117
+ rubygems_version: 3.1.2
114
118
  signing_key:
115
119
  specification_version: 4
116
120
  summary: Namespaces Redis commands.