redis-namespace 1.7.0 → 1.8.2

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: 0541ad1ce3251b5dc3c035e47aa0690d334d32b9c5b29e335604570cb5847dac
4
+ data.tar.gz: '0877ceadbd1afa44a38fd1b7bb7af4b0e9e87a3426f688c891c847853588f65a'
5
5
  SHA512:
6
- metadata.gz: e05aa113c14df634a64fdfad7891781ace6a5060a533e9417f94476235f3e05fd33859c4653fcbe8f417582e9257cdf20b1599ac1b2e4cbe38ccaf7c88af2dba
7
- data.tar.gz: 220e3ec476e5613dd3a8529f2f7b30f7aba9433a1f4ab4402c55be555ef00ff5651738824ddc583e83e7cbad9297d1f1a107bd61e4b44df5e8c9efa50589cfea
6
+ metadata.gz: 9c8cd0be52f98f4fe16b551ac261faba1db4da269a07ac9c85e4a8a4b20347c0a4646036bc5fb64cab3d5863d88b308f15ea96996fd19bfad8bd85980ccf5081
7
+ data.tar.gz: 1d6e8e911c9bf887ff00cead444978ecfcccd6f2b04c56549fd28542864e7971ca9f4e5510d2e7473efb91bac50be8ac7d7cd9555fea5ca0da63d8b374d3e793
data/README.md CHANGED
@@ -79,7 +79,7 @@ namespaced.redis.flushall()
79
79
 
80
80
  As mentioned above, 2.0 will remove blind passthrough and the administrative command passthrough.
81
81
  By default in 1.5+, deprecation warnings are present and enabled;
82
- they can be silenced by initializing `Redis::Namespace` with `warnings: false` or by setting the `REDIS_NAMESPACE_QUIET` environment variable.
82
+ they can be silenced by initializing `Redis::Namespace` with `warning: false` or by setting the `REDIS_NAMESPACE_QUIET` environment variable.
83
83
 
84
84
  Early opt-in
85
85
  ------------
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Redis
4
4
  class Namespace
5
- VERSION = '1.7.0'
5
+ VERSION = '1.8.2'
6
6
  end
7
7
  end
@@ -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,26 @@ class Redis
483
490
 
484
491
  result
485
492
  end
493
+ ruby2_keywords(:call_with_namespace) if respond_to?(:ruby2_keywords, true)
494
+
495
+ protected
496
+
497
+ def redis=(redis)
498
+ @redis = redis
499
+ end
486
500
 
487
501
  private
488
502
 
503
+ if Hash.respond_to?(:ruby2_keywords_hash)
504
+ def ruby2_keywords_hash(kwargs)
505
+ Hash.ruby2_keywords_hash(kwargs)
506
+ end
507
+ else
508
+ def ruby2_keywords_hash(kwargs)
509
+ kwargs
510
+ end
511
+ end
512
+
489
513
  # Avoid modifying the caller's (pass-by-reference) arguments.
490
514
  def clone_args(arg)
491
515
  if arg.is_a?(Array)
@@ -502,12 +526,13 @@ class Redis
502
526
  end
503
527
 
504
528
  def namespaced_block(command, &block)
505
- redis.send(command) do |r|
506
- begin
507
- original, @redis = @redis, r
508
- yield self
509
- ensure
510
- @redis = original
529
+ if block.arity == 0
530
+ redis.send(command, &block)
531
+ else
532
+ redis.send(command) do |r|
533
+ copy = dup
534
+ copy.redis = r
535
+ yield copy
511
536
  end
512
537
  end
513
538
  end
data/spec/redis_spec.rb CHANGED
@@ -6,25 +6,14 @@ describe "redis" do
6
6
  @redis_version = Gem::Version.new(Redis.current.info["redis_version"])
7
7
  let(:redis_client) { @redis.respond_to?(:_client) ? @redis._client : @redis.client}
8
8
 
9
- before(:all) do
9
+ before(:each) do
10
10
  # use database 15 for testing so we dont accidentally step on your real data
11
11
  @redis = Redis.new :db => 15
12
- end
13
-
14
- before(:each) do
15
- @namespaced = Redis::Namespace.new(:ns, :redis => @redis)
16
12
  @redis.flushdb
13
+ @namespaced = Redis::Namespace.new(:ns, :redis => @redis)
17
14
  @redis.set('foo', 'bar')
18
15
  end
19
16
 
20
- after(:each) do
21
- @redis.flushdb
22
- end
23
-
24
- after(:all) do
25
- @redis.quit
26
- end
27
-
28
17
  # redis-rb 3.3.4+
29
18
  it "should inject :namespace into connection info" do
30
19
  info = @redis.connection.merge(:namespace => :ns)
@@ -140,10 +129,22 @@ describe "redis" do
140
129
 
141
130
  it 'should be able to use a namespace with setbit' do
142
131
  @namespaced.setbit('virgin_key', 1, 1)
143
- expect(@namespaced.exists('virgin_key')).to be true
132
+ expect(@namespaced.exists?('virgin_key')).to be true
144
133
  expect(@namespaced.get('virgin_key')).to eq(@namespaced.getrange('virgin_key',0,-1))
145
134
  end
146
135
 
136
+ it 'should be able to use a namespace with exists' do
137
+ @namespaced.set('foo', 1000)
138
+ @namespaced.set('bar', 2000)
139
+ expect(@namespaced.exists('foo', 'bar')).to eq(2)
140
+ end
141
+
142
+ it 'should be able to use a namespace with exists?' do
143
+ @namespaced.set('foo', 1000)
144
+ @namespaced.set('bar', 2000)
145
+ expect(@namespaced.exists?('does_not_exist', 'bar')).to eq(true)
146
+ end
147
+
147
148
  it 'should be able to use a namespace with bitpos' do
148
149
  @namespaced.setbit('bit_map', 42, 1)
149
150
  expect(@namespaced.bitpos('bit_map', 0)).to eq(0)
@@ -239,7 +240,7 @@ describe "redis" do
239
240
  @namespaced.zadd('sort2', 2, 2)
240
241
  @namespaced.zadd('sort2', 3, 3)
241
242
  @namespaced.zadd('sort2', 4, 4)
242
- @namespaced.zunionstore('union', ['sort1', 'sort2'], :weights => [2, 1])
243
+ @namespaced.zunionstore('union', ['sort1', 'sort2'], weights: [2, 1])
243
244
  expect(@namespaced.zrevrange('union', 0, -1)).to eq(%w( 2 4 3 1 ))
244
245
  end
245
246
 
@@ -386,6 +387,27 @@ describe "redis" do
386
387
  expect(result).to eq(["bar", "value"])
387
388
  end
388
389
 
390
+ it "is thread safe for multi blocks" do
391
+ mon = Monitor.new
392
+ entered = false
393
+ entered_cond = mon.new_cond
394
+
395
+ thread = Thread.new do
396
+ mon.synchronize do
397
+ entered_cond.wait_until { entered }
398
+ @namespaced.multi
399
+ end
400
+ end
401
+
402
+ @namespaced.multi do |transaction|
403
+ entered = true
404
+ mon.synchronize { entered_cond.signal }
405
+ thread.join(0.1)
406
+ transaction.get("foo")
407
+ end
408
+ thread.join
409
+ end
410
+
389
411
  it "should add namespace to strlen" do
390
412
  @namespaced.set("mykey", "123456")
391
413
  expect(@namespaced.strlen("mykey")).to eq(6)
@@ -442,6 +464,45 @@ describe "redis" do
442
464
  expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
443
465
  end
444
466
 
467
+ describe '#inspect' do
468
+ let(:single_level_names) { %i[first] }
469
+ let(:double_level_names) { %i[first second] }
470
+ let(:triple_level_names) { %i[first second third] }
471
+ let(:namespace_builder) do
472
+ ->(redis, *namespaces) { namespaces.reduce(redis) { |r, n| Redis::Namespace.new(n, redis: r) } }
473
+ end
474
+ let(:regexp_builder) do
475
+ ->(*namespaces) { %r{/#{namespaces.join(':')}>\z} }
476
+ end
477
+
478
+ context 'when one namespace' do
479
+ let(:single_namespaced) { namespace_builder.call(@redis, *single_level_names) }
480
+ let(:regexp) { regexp_builder.call(*single_level_names) }
481
+
482
+ it 'should have correct ending of inspect string' do
483
+ expect(regexp =~ single_namespaced.inspect).not_to be(nil)
484
+ end
485
+ end
486
+
487
+ context 'when two namespaces' do
488
+ let(:double_namespaced) { namespace_builder.call(@redis, *double_level_names) }
489
+ let(:regexp) { regexp_builder.call(*double_level_names) }
490
+
491
+ it 'should have correct ending of inspect string' do
492
+ expect(regexp =~ double_namespaced.inspect).not_to be(nil)
493
+ end
494
+ end
495
+
496
+ context 'when three namespaces' do
497
+ let(:triple_namespaced) { namespace_builder.call(@redis, *triple_level_names) }
498
+ let(:regexp) { regexp_builder.call(*triple_level_names) }
499
+
500
+ it 'should have correct ending of inspect string' do
501
+ expect(regexp =~ triple_namespaced.inspect).not_to be(nil)
502
+ end
503
+ end
504
+ end
505
+
445
506
  # Redis 2.6 RC reports its version as 2.5.
446
507
  if @redis_version >= Gem::Version.new("2.5.0")
447
508
  describe "redis 2.6 commands" do
data/spec/spec_helper.rb CHANGED
@@ -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,17 +1,17 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
8
8
  - Terence Lee
9
9
  - Steve Klabnik
10
10
  - Ryan Biesemeyer
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-12-11 00:00:00.000000000 Z
14
+ date: 2022-03-07 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,17 +91,21 @@ 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: {}
98
- post_install_message:
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.2
101
+ source_code_uri: https://github.com/resque/redis-namespace/tree/v1.8.2
102
+ post_install_message:
99
103
  rdoc_options: []
100
104
  require_paths:
101
105
  - lib
102
106
  required_ruby_version: !ruby/object:Gem::Requirement
103
107
  requirements:
104
- - - "~>"
108
+ - - ">="
105
109
  - !ruby/object:Gem::Version
106
110
  version: '2.4'
107
111
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -110,8 +114,8 @@ 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
114
- signing_key:
117
+ rubygems_version: 3.1.2
118
+ signing_key:
115
119
  specification_version: 4
116
120
  summary: Namespaces Redis commands.
117
121
  test_files: []