Skip to content

Commit

Permalink
Merge pull request #1022 from godric/master
Browse files Browse the repository at this point in the history
Improve empty stream responses deserialization
  • Loading branch information
byroot authored Aug 3, 2021
2 parents 5dd7df9 + 2e85516 commit 97742e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3518,7 +3518,7 @@ def method_missing(command, *args) # rubocop:disable Style/MissingRespondToMissi

HashifyStreamEntries = lambda { |reply|
reply.compact.map do |entry_id, values|
[entry_id, values.each_slice(2).to_h]
[entry_id, values&.each_slice(2)&.to_h]
end
}

Expand Down
11 changes: 11 additions & 0 deletions test/lint/streams.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,17 @@ def test_xreadgroup_with_invalid_arguments
assert_raises(Redis::CommandError) { redis.xreadgroup('g1', 'c1', 's1', %w[> >]) }
end

def test_xreadgroup_a_trimmed_entry
redis.xgroup(:create, 'k1', 'g1', '0', mkstream: true)
entry_id = redis.xadd('k1', { value: 'v1' })

assert_equal({ 'k1' => [[entry_id, { 'value' => 'v1' }]] }, redis.xreadgroup('g1', 'c1', 'k1', '>'))
assert_equal({ 'k1' => [[entry_id, { 'value' => 'v1' }]] }, redis.xreadgroup('g1', 'c1', 'k1', '0'))
redis.xtrim('k1', 0)

assert_equal({ 'k1' => [[entry_id, nil]] }, redis.xreadgroup('g1', 'c1', 'k1', '0'))
end

def test_xack_with_a_entry_id
redis.xadd('s1', { f: 'v1' }, id: '0-1')
redis.xgroup(:create, 's1', 'g1', '$')
Expand Down

0 comments on commit 97742e0

Please sign in to comment.