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 1 commit
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
18 changes: 18 additions & 0 deletions test/streams_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require_relative "helper"

class TestStreams < Minitest::Test
include Helper::Client

def test_read_a_trimmed_entry
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in https://github.com/redis/redis-rb/blob/master/test/lint/streams.rb (that will give you the automatic skip if redis is too old)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the test and moved it with other xreadgroup tests ✅

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

assert_equal r.xreadgroup('g1', 'c1', 'k1', '>'), { 'k1' => [[entry_id, { 'value' => 'v1' }]] }
byroot marked this conversation as resolved.
Show resolved Hide resolved
assert_equal r.xreadgroup('g1', 'c1', 'k1', '0'), { 'k1' => [[entry_id, { 'value' => 'v1' }]] }
r.xtrim('k1', 0)

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