3 -export([parse/2, parse_int/2, parse_types/2,
4 parse_string/2, stateful_parser/2,
5 single_stateful_parser/2, parse_special/2]).
10 parse(empty, "+PONG") ->
23 {error, argument_out_of_range};
24 parse(empty, "-" ++ Message) ->
27 parse_special(empty, "-1") ->
29 parse_special(empty, "-2") ->
31 parse_special(empty, N) ->
34 parse_int(empty, "-ERR " ++ Message) ->
36 parse_int(empty, Value) ->
37 list_to_integer(Value).
39 parse_string(empty, Message) ->
42 parse_types(empty, "none") -> none;
43 parse_types(empty, "string") -> string;
44 parse_types(empty, "list") -> list;
45 parse_types(empty, "set") -> set.
48 % I'm used when redis returns multiple results
49 stateful_parser(empty, "nil") ->
51 stateful_parser(error, "-ERR " ++ Error) ->
53 stateful_parser(empty, "-" ++ _ErrorLength) ->
55 stateful_parser(empty, NumberOfElements) ->
56 {hold, list_to_integer(NumberOfElements)};
57 stateful_parser(read, ElementSize) ->
58 {read, list_to_integer(ElementSize)}.
60 % I'm used when redis returns just one result
61 single_stateful_parser(empty, "nil") ->
63 single_stateful_parser(error, "-ERR " ++ Error) ->
65 single_stateful_parser(empty, "-" ++ _ErrorLength) ->
67 single_stateful_parser(empty, ElementSize) ->
68 {read, list_to_integer(ElementSize)}.