Skip to content

Commit

Permalink
Merge pull request #1272 from braze-inc/pipeline-multi-getall-not-hash
Browse files Browse the repository at this point in the history
[master] Fix response of `multi` in `pipelined` for #1271
  • Loading branch information
byroot authored Apr 30, 2024
2 parents bdb8341 + b1e5810 commit 48f76d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/redis/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ def initialize(futures)
end

def _set(replies)
if replies
@futures.each_with_index do |future, index|
@object = if replies
@futures.map.with_index do |future, index|
future._set(replies[index])
future.value
end
else
replies
end
@object = replies
end
end
end
17 changes: 17 additions & 0 deletions test/redis/pipelining_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ def test_zpopmax_in_a_pipeline_produces_future
assert_equal ["value", 1.0], future.value
end

def test_hgetall_in_a_multi_in_a_pipeline_returns_hash
future = nil
result = r.pipelined do |p|
p.multi do |m|
m.hmset("hash", "field", "value", "field2", "value2")
future = m.hgetall("hash")
end
end

if Gem::Version.new(Redis::VERSION) > Gem::Version.new("4.8")
result = result.last
end

assert_equal({ "field" => "value", "field2" => "value2" }, result.last)
assert_equal({ "field" => "value", "field2" => "value2" }, future.value)
end

def test_keys_in_a_pipeline
r.set("key", "value")
result = r.pipelined do |p|
Expand Down

0 comments on commit 48f76d7

Please sign in to comment.