diff --git a/lib/redis_client/ruby_connection/buffered_io.rb b/lib/redis_client/ruby_connection/buffered_io.rb index b852637..9968f3c 100644 --- a/lib/redis_client/ruby_connection/buffered_io.rb +++ b/lib/redis_client/ruby_connection/buffered_io.rb @@ -194,6 +194,14 @@ def fill_buffer(strict, size = @chunk_size) start = @offset - buffer_size empty_buffer = start >= 0 + if !empty_buffer && @offset > (@chunk_size * 2) + old_buffer = @buffer + @buffer = @buffer.byteslice(@offset..-1) + old_buffer.clear + @offset = 0 + start = @offset - @buffer.bytesize + end + loop do bytes = if empty_buffer @io.read_nonblock([remaining, @chunk_size].max, @buffer, exception: false)