Skip to content

Commit 38db08c

Browse files
author
Stefan Wille
committed
Fix issue #8 - 'Bug when getting a value over 8K in length'
1 parent bcc9c2b commit 38db08c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

spec/redis_spec.cr

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,4 +1104,15 @@ describe Redis do
11041104
callbacks_received.should eq(["psubscribe", "pmessage", "punsubscribe"])
11051105
end
11061106
end
1107+
1108+
describe "large values" do
1109+
redis = Redis.new
1110+
1111+
it "sends and receives a large value correctly" do
1112+
redis.del("foo")
1113+
large_value = "0123456789" * 100_000 # 1 MB
1114+
redis.set("foo", large_value)
1115+
redis.get("foo").should eq(large_value)
1116+
end
1117+
end
11071118
end

src/redis/connection.cr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ class Redis::Connection
8787
# The "Null bulk string" aka nil
8888
return nil if length == -1
8989

90-
slice = Slice(UInt8).new(length)
91-
@socket.read(slice)
92-
bulk_string = String.new(slice)
90+
bulk_string = String.new(length) do |buffer|
91+
@socket.read_fully(Slice.new(buffer, length))
92+
{length, 0}
93+
end
9394
# Ignore CR/LF
9495
@socket.skip(2)
9596
bulk_string

0 commit comments

Comments
 (0)