Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve empty stream responses deserialization #1022

Merged
merged 3 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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