redis-namespace 1.7.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redis/namespace.rb +22 -4
- data/lib/redis/namespace/version.rb +1 -1
- data/spec/redis_spec.rb +53 -2
- data/spec/spec_helper.rb +4 -0
- metadata +17 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 781a6361b78e31842c9fe934161b83e1acf9d1c1ef50cd015694b78582b461ac
|
4
|
+
data.tar.gz: a0856e98fb69b1063c460ef1479dd57a4659741612b398d3fac2d4bb3727e1b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caf163b05d1f4c5f08a29d4d1f977d666f1a627b582af762f50d883df64f0f2139fe132918edbc6c59d9259f386f7ed7a094da3493579072f25d9c957da7e7eb
|
7
|
+
data.tar.gz: 951f20c3aaedd77400f34b161fb642d39ff0a4e8a619506441288f6671043a3bfd3e1f18e13a62fc8e014f79d989246fcb51b351f4d3f1b6f3a2a6ce8f17bd41
|
data/lib/redis/namespace.rb
CHANGED
@@ -68,7 +68,8 @@ class Redis
|
|
68
68
|
"decrby" => [ :first ],
|
69
69
|
"del" => [ :all ],
|
70
70
|
"dump" => [ :first ],
|
71
|
-
"exists" => [ :
|
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}/#{
|
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)
|
data/spec/redis_spec.rb
CHANGED
@@ -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'], :
|
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
|
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.
|
4
|
+
version: 1.8.1
|
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:
|
14
|
+
date: 2021-02-04 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: '
|
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: '
|
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:
|
94
|
+
homepage: https://github.com/resque/redis-namespace
|
95
95
|
licenses:
|
96
96
|
- MIT
|
97
|
-
metadata:
|
98
|
-
|
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.1
|
101
|
+
source_code_uri: https://github.com/resque/redis-namespace/tree/v1.8.1
|
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.
|
114
|
-
signing_key:
|
117
|
+
rubygems_version: 3.1.4
|
118
|
+
signing_key:
|
115
119
|
specification_version: 4
|
116
120
|
summary: Namespaces Redis commands.
|
117
121
|
test_files: []
|