Skip to content

Commit

Permalink
Merge pull request #146 from swanson/swanson/failing-nil-test
Browse files Browse the repository at this point in the history
Kredis.hash fails with nil values in Redis 5+
  • Loading branch information
rafaelfranca committed Feb 27, 2024
2 parents 4fbb2f5 + eb68a92 commit 1324561
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kredis/types/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def []=(key, value)
end

def update(**entries)
hset entries.transform_values { |val| type_to_string(val, typed) } if entries.flatten.any?
hset entries.transform_values { |val| type_to_string(val, typed) }.compact if entries.flatten.any?
end

def values_at(*keys)
Expand Down
6 changes: 6 additions & 0 deletions test/types/hash_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ class HashTest < ActiveSupport::TestCase
@hash = Kredis.hash "myhash", typed: :integer, default: ->() { { space_invaders: "100", pong: "42" } }
assert_equal({ "space_invaders" => 100, "pong" => 42 }, @hash.to_h)
end

test "handles nil values gracefully" do
@hash.update("key" => nil, "key2" => "value2")
assert_nil @hash["key"]
assert_equal "value2", @hash["key2"]
end
end

0 comments on commit 1324561

Please sign in to comment.