diff --git a/lib/redis/connection/ruby.rb b/lib/redis/connection/ruby.rb index f2fbc2c05..68c7e84ef 100644 --- a/lib/redis/connection/ruby.rb +++ b/lib/redis/connection/ruby.rb @@ -68,6 +68,7 @@ def _read_from_socket(nbytes) end def _write_to_socket(data) + data = data.b total_bytes_written = 0 loop do case bytes_written = write_nonblock(data, exception: false) @@ -95,7 +96,6 @@ def _write_to_socket(data) def write(data) return super(data) unless @write_timeout - data = data.b length = data.bytesize total_count = 0 loop do diff --git a/test/internals_test.rb b/test/internals_test.rb index e19b56690..82ad78ef6 100644 --- a/test/internals_test.rb +++ b/test/internals_test.rb @@ -12,6 +12,16 @@ def test_logger assert log.string =~ /\[Redis\] call_time=\d+\.\d+ ms/ end + def test_large_payload + # see: https://github.com/redis/redis-rb/issues/962 + # large payloads will trigger write_nonblock to write a portion + # of the payload in connection/ruby.rb _write_to_socket + large = "\u3042" * 4_000_000 + r.setex("foo", 10, large) + result = r.get("foo") + assert_equal result, large + end + def test_logger_with_pipelining r.pipelined do r.set "foo", "bar"