Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
test: checking nested bulk replies
Browse files Browse the repository at this point in the history
  • Loading branch information
agladysh committed Dec 28, 2012
1 parent 861b5f8 commit 6d55698
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,60 @@ assert(

--------------------------------------------------------------------------------

do
local info = assert(hiredis.unwrap_reply(conn:command("INFO")))
local major, minor = info:find("redis_version:%s*(%d+)%.(%d+)")
if not major or not minor then
error("can't determine Redis version from INFO command")
elseif tonumber(major) < 2 or tonumber(minor) < 6 then
print("Redis version <2.6, skipping nested bulk test")
else
-- Based on a real bug scenario:
-- https://github.com/agladysh/lua-hiredis/issues/2
-- Note that hiredis C library has built in limitation
-- on bulk reply nesting.
do
local r = assert(
hiredis.unwrap_reply(
conn:command(
"EVAL",
[[return { 1, { 2, { 3 }, 4 }, 5 }]],
0
)
)
)
assert(type(r) == "table")
assert(r[1] == 1)
assert(r[2][1] == 2)
assert(r[2][2][1] == 3)
assert(r[2][3] == 4)
assert(r[3] == 5)
end

do
local r = assert(
hiredis.unwrap_reply(
conn:command(
"EVAL",
[[return { 1, { 2, { 3, { 4 }, 5 }, 6 }, 7 }]],
0
)
)
)
assert(type(r) == "table")
assert(r[1] == 1)
assert(r[2][1] == 2)
assert(r[2][2][1] == 3)
assert(r[2][2][2][1] == 4)
assert(r[2][2][3] == 5)
assert(r[2][3] == 6)
assert(r[3] == 7)
end
end
end

--------------------------------------------------------------------------------

conn:close()
conn:close() -- double close check
conn = nil
Expand Down

0 comments on commit 6d55698

Please sign in to comment.