Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle nil multi-bulk replies.

  • Loading branch information...
commit ddec585de87fb2bb6015f572a034ff6f7fd51f09 1 parent f469a46
@jdavisp3 jdavisp3 authored knutin committed
View
2  src/eredis_parser.erl
@@ -149,6 +149,8 @@ parse_multibulk({in_parsing_bulks, Count, OldData, Acc},
do_parse_multibulk(Count, Data) ->
do_parse_multibulk(Count, Data, []).
+do_parse_multibulk(-1, Data, []) ->
+ {ok, undefined, Data};
do_parse_multibulk(0, Data, Acc) ->
{ok, lists:reverse(Acc), Data};
do_parse_multibulk(Count, <<>>, Acc) ->
View
8 test/eredis_parser_tests.erl
@@ -232,6 +232,14 @@ multibulk_newline_split_test() ->
?assertEqual({ok, [<<"1">>, <<"2">>], <<>>}, parse_multibulk(ContinuationData1, B2)).
+multibulk_nil_test() ->
+ B = <<"*-1\r\n">>,
+ ?assertEqual({ok, undefined, <<>>}, parse_multibulk(B)).
+
+multibulk_nil_parse_test() ->
+ B = <<"*-1\r\n">>,
+ ?assertEqual({ok, undefined, #pstate{}}, parse(init(), B)).
+
big_chunks_test() ->
%% Real-world example, MGET 1..200
B1 = <<"*200\r\n$1\r\n1\r\n$1\r\n2\r\n$1\r\n3\r\n$1\r\n4\r\n$1\r\n5\r\n$1\r\n6\r\n$1\r\n7\r\n$1\r\n8\r\n$1\r\n9\r\n$2\r\n10\r\n$2\r\n11\r\n$2\r\n12\r\n$2\r\n13\r\n$2\r\n14\r\n$2\r\n15\r\n$2\r\n16\r\n$2\r\n17\r\n$2\r\n18\r\n$2\r\n19\r\n$2\r\n20\r\n$2\r\n21\r\n$2\r\n22\r\n$2\r\n23\r\n$2\r\n24\r\n$2\r\n25\r\n$2\r\n26\r\n$2\r\n27\r\n$2\r\n28\r\n$2\r\n29\r\n$2\r\n30\r\n$2\r\n31\r\n$2\r\n32\r\n$2\r\n33\r\n$2\r\n34\r\n$2\r\n35\r\n$2\r\n36\r\n$2\r\n37\r\n$2\r\n38\r\n$2\r\n39\r\n$2\r\n40\r\n$2\r\n41\r\n$2\r\n42\r\n$2\r\n43\r\n$2\r\n44\r\n$2\r\n45\r\n$2\r\n46\r\n$2\r\n47\r\n$2\r\n48\r\n$2\r\n49\r\n$2\r\n50\r\n$2\r\n51\r\n$2\r\n52\r\n$2\r\n53\r\n$2\r\n54\r\n$2\r\n55\r\n$2\r\n56\r\n$2\r\n57\r\n$2\r\n58\r\n$2\r\n59\r\n$2\r\n60\r\n$2\r\n61\r\n$2\r\n62\r\n$2\r\n63\r\n$2\r\n64\r\n$2\r\n65\r\n$2\r\n66\r\n$2\r\n67\r\n$2\r\n68\r\n$2\r\n69\r\n$2\r\n70\r\n$2\r\n71\r\n$2\r\n72\r\n$2\r\n73\r\n$2\r\n74\r\n$2\r\n75\r\n$2\r\n76\r\n$2\r\n77\r\n$2\r\n78\r\n$2\r\n79\r\n$2\r\n80\r\n$2\r\n81\r\n$2\r\n82\r\n$2\r\n83\r\n$2\r\n84\r\n$2\r\n85\r\n$2\r\n86\r\n$2\r\n87\r\n$2\r\n88\r\n$2\r\n89\r\n$2\r\n90\r\n$2\r\n91\r\n$2\r\n92\r\n$2\r\n93\r\n$2\r\n94\r\n$2\r\n95\r\n$2\r\n96\r\n$2\r\n97\r\n$2\r\n98\r\n$2\r\n99\r\n$3\r\n100\r\n$3\r\n101\r\n$3\r\n102\r\n$3\r\n103\r\n$3\r\n104\r\n$3\r\n105\r\n$3\r\n106\r\n$3\r\n107\r\n$3\r\n108\r\n$3\r\n109\r\n$3\r\n110\r\n$3\r\n111\r\n$3\r\n112\r\n$3\r\n113\r\n$3\r\n114\r\n$3\r\n115\r\n$3\r\n116\r\n$3\r\n117\r\n$3\r\n118\r\n$3\r\n119\r\n$3\r\n120\r\n$3\r\n121\r\n$3\r\n122\r\n$3\r\n123\r\n$3\r\n124\r\n$3\r\n125\r\n$3\r\n126\r\n$3\r\n127\r\n$3\r\n128\r\n$3\r\n129\r\n$3\r\n130\r\n$3\r\n131\r\n$3\r\n132\r\n$3\r\n133\r\n$3\r\n134\r\n$3\r\n135\r\n$3\r\n136\r\n$3\r\n137\r\n$3\r\n138\r\n$3\r\n139\r\n$3\r\n140\r\n$3\r\n141\r\n$3\r\n142\r\n$3\r\n143\r\n$3\r\n144\r\n$3\r\n145\r\n$3\r\n146\r\n$3\r\n147\r\n$3\r\n148\r\n$3\r\n149\r\n$3\r\n150\r\n$3\r\n151\r\n$3\r\n152\r\n$3\r\n153\r\n$3\r\n154\r\n$3\r\n155\r\n$3\r\n156\r\n$3\r\n157\r\n$3\r\n158\r\n$3\r\n159\r\n$3\r\n160\r\n$3\r\n161\r\n$3\r\n162\r\n$3\r\n163\r\n$3\r\n164\r\n$3\r\n165\r\n$3\r\n166\r\n$3\r\n167\r\n$3\r\n168\r\n$3\r\n169\r\n$3\r\n170\r\n$3\r\n171\r\n$3\r\n172\r\n$3\r\n173\r\n$3\r\n1">>,
View
10 test/eredis_tests.erl
@@ -51,6 +51,16 @@ exec_test() ->
?assertMatch({ok, _}, eredis:q(C, ["DEL", "k1", "k2"])).
+exec_nil_test() ->
+ C1 = c(),
+ C2 = c(),
+
+ ?assertEqual({ok, <<"OK">>}, eredis:q(C1, ["WATCH", "x"])),
+ ?assertMatch({ok, _}, eredis:q(C2, ["INCR", "x"])),
+ ?assertEqual({ok, <<"OK">>}, eredis:q(C1, ["MULTI"])),
+ ?assertEqual({ok, <<"QUEUED">>}, eredis:q(C1, ["GET", "x"])),
+ ?assertEqual({ok, undefined}, eredis:q(C1, ["EXEC"])),
+ ?assertMatch({ok, _}, eredis:q(C1, ["DEL", "x"])).
pipeline_test() ->
C = c(),
Please sign in to comment.
Something went wrong with that request. Please try again.