Skip to content

Commit

Permalink
Fix issue #8 - 'Bug when getting a value over 8K in length'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Wille committed Nov 12, 2015
1 parent bcc9c2b commit 38db08c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions spec/redis_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1104,4 +1104,15 @@ describe Redis do
callbacks_received.should eq(["psubscribe", "pmessage", "punsubscribe"])
end
end

describe "large values" do
redis = Redis.new

it "sends and receives a large value correctly" do
redis.del("foo")
large_value = "0123456789" * 100_000 # 1 MB
redis.set("foo", large_value)
redis.get("foo").should eq(large_value)
end
end
end
7 changes: 4 additions & 3 deletions src/redis/connection.cr
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ class Redis::Connection
# The "Null bulk string" aka nil
return nil if length == -1

slice = Slice(UInt8).new(length)
@socket.read(slice)
bulk_string = String.new(slice)
bulk_string = String.new(length) do |buffer|
@socket.read_fully(Slice.new(buffer, length))
{length, 0}
end
# Ignore CR/LF
@socket.skip(2)
bulk_string
Expand Down

0 comments on commit 38db08c

Please sign in to comment.