Skip to content

Commit e282846

Browse files
committed
Add final namespace prefix to inspect
Previously, if you have a nested redis inspect showed you only last namespace, for example: parent = Redis::Namespace.new(:parent) child = Redis::Namespace.new(:child, parent) child.inspect # => <Redis::Namespace v1.6.0 with client v4.1.3 for redis://127.0.0.1:6379/0/child> But now inspect shows full prefix, by which key will be stored in redis: child.inspect # => <Redis::Namespace v1.6.0 with client v4.1.3 for redis://127.0.0.1:6379/0/parent:child>
1 parent 54066a5 commit e282846

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

lib/redis/namespace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def method_missing(command, *args, &block)
373373

374374
def inspect
375375
"<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\
376-
"for #{@redis.id}/#{@namespace}>"
376+
"for #{@redis.id}/#{full_namespace}>"
377377
end
378378

379379
def respond_to_missing?(command, include_all=false)

spec/redis_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,45 @@
442442
expect { @namespaced.unknown('foo') }.to raise_exception NoMethodError
443443
end
444444

445+
describe '#inspect' do
446+
let(:single_level_names) { %i[first] }
447+
let(:double_level_names) { %i[first second] }
448+
let(:triple_level_names) { %i[first second third] }
449+
let(:namespace_builder) do
450+
->(redis, *namespaces) { namespaces.reduce(redis) { |r, n| Redis::Namespace.new(n, redis: r) } }
451+
end
452+
let(:regexp_builder) do
453+
->(*namespaces) { %r{/#{namespaces.join(':')}>\z} }
454+
end
455+
456+
context 'when one namespace' do
457+
let(:single_namespaced) { namespace_builder.call(@redis, *single_level_names) }
458+
let(:regexp) { regexp_builder.call(*single_level_names) }
459+
460+
it 'should have correct ending of inspect string' do
461+
expect(regexp =~ single_namespaced.inspect).not_to be(nil)
462+
end
463+
end
464+
465+
context 'when two namespaces' do
466+
let(:double_namespaced) { namespace_builder.call(@redis, *double_level_names) }
467+
let(:regexp) { regexp_builder.call(*double_level_names) }
468+
469+
it 'should have correct ending of inspect string' do
470+
expect(regexp =~ double_namespaced.inspect).not_to be(nil)
471+
end
472+
end
473+
474+
context 'when three namespaces' do
475+
let(:triple_namespaced) { namespace_builder.call(@redis, *triple_level_names) }
476+
let(:regexp) { regexp_builder.call(*triple_level_names) }
477+
478+
it 'should have correct ending of inspect string' do
479+
expect(regexp =~ triple_namespaced.inspect).not_to be(nil)
480+
end
481+
end
482+
end
483+
445484
# Redis 2.6 RC reports its version as 2.5.
446485
if @redis_version >= Gem::Version.new("2.5.0")
447486
describe "redis 2.6 commands" do

0 commit comments

Comments
 (0)