Skip to content

Commit

Permalink
Merge pull request #201 from fatkodima/mset-arrays
Browse files Browse the repository at this point in the history
Fix mset/msetnx to handle key/value pairs passed as arrays
  • Loading branch information
byroot committed Jul 4, 2022
2 parents f2f6016 + f45b08f commit d578eb5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/redis/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ def call_with_namespace(command, *args, &block)
args = add_namespace(args)
end
when :alternate
args = args.flatten
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]
Expand Down
7 changes: 7 additions & 0 deletions spec/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,22 @@
@namespaced.mset('foo', '1000', 'bar', '2000')
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})

@namespaced.mapped_mset('foo' => '3000', 'bar' => '5000')
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000' })
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})

@namespaced.mset(['foo', '4000'], ['baz', '6000'])
expect(@namespaced.mapped_mget('foo', 'bar', 'baz')).to eq({ 'foo' => '4000', 'bar' => '5000', 'baz' => '6000' })
end

it "should be able to use a namespace with msetnx" do
@namespaced.msetnx('foo', '1000', 'bar', '2000')
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})

@namespaced.msetnx(['baz', '4000'])
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => '4000'})
end

it "should be able to use a namespace with mapped_msetnx" do
Expand Down

0 comments on commit d578eb5

Please sign in to comment.