diff --git a/lib/redis/namespace.rb b/lib/redis/namespace.rb index fa3b34d..f06f2f6 100644 --- a/lib/redis/namespace.rb +++ b/lib/redis/namespace.rb @@ -36,7 +36,7 @@ class Namespace # MSET key1 value1 key2 value2 => # MSET namespace:key1 value1 namespace:key2 value2 # :sort - # Add namespace to first argument if it is non-nil + # Add namespace to first argument # Add namespace to second arg's :by and :store if second arg is a Hash # Add namespace to each element in second arg's :get if second arg is # a Hash; forces second arg's :get to be an Array if present. @@ -366,7 +366,7 @@ def call_with_namespace(command, *args, &block) # Add the namespace to any parameters that are keys. case before when :first - args[0] = add_namespace(args[0]) if args[0] + args[0] = add_namespace(args[0]) when :all args = add_namespace(args) when :exclude_first @@ -388,7 +388,7 @@ def call_with_namespace(command, *args, &block) when :alternate args.each_with_index { |a, i| args[i] = add_namespace(a) if i.even? } when :sort - args[0] = add_namespace(args[0]) if args[0] + args[0] = add_namespace(args[0]) if args[1].is_a?(Hash) [:by, :store].each do |key| args[1][key] = add_namespace(args[1][key]) if args[1][key] @@ -464,7 +464,7 @@ def namespaced_block(command, &block) end def add_namespace(key) - return key unless key && @namespace + return key unless @namespace case key when Array diff --git a/spec/redis_spec.rb b/spec/redis_spec.rb index 885b4dc..647a37e 100644 --- a/spec/redis_spec.rb +++ b/spec/redis_spec.rb @@ -32,6 +32,7 @@ @namespaced['foo'].should eq(nil) @namespaced['foo'] = 'chris' @namespaced['foo'].should eq('chris') + @redis['foo'].should eq('bar') @redis['foo'] = 'bob' @redis['foo'].should eq('bob') @@ -41,6 +42,17 @@ @namespaced.type('counter').should eq('string') end + context 'when key is nil' do + it 'should still be able to use a namespace' do + @namespaced[nil].should eq(nil) + @namespaced[nil] = 'chris' + @namespaced[nil].should eq('chris') + @redis[nil].should eq(nil) + @redis[nil] = 'bob' + @redis[nil].should eq('bob') + end + end + context 'when sending capital commands (issue 68)' do it 'should be able to use a namespace' do @namespaced.send('SET', 'fubar', 'quux')