]> git.saurik.com Git - redis.git/blob - client-libraries/erlang/src/proto.erl
New file dump format, perl client library added
[redis.git] / client-libraries / erlang / src / proto.erl
1 -module(proto).
2
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]).
6
7
8 parse(empty, "+OK") ->
9 ok;
10 parse(empty, "+PONG") ->
11 pong;
12 parse(empty, "0") ->
13 false;
14 parse(empty, "1") ->
15 true;
16 parse(empty, "-1") ->
17 {error, no_such_key};
18 parse(empty, "-2") ->
19 {error, wrong_type};
20 parse(empty, "-3") ->
21 {error, same_db};
22 parse(empty, "-4") ->
23 {error, argument_out_of_range};
24 parse(empty, "-" ++ Message) ->
25 {error, Message}.
26
27 parse_special(empty, "-1") ->
28 parse(empty, "-1");
29 parse_special(empty, "-2") ->
30 parse(empty, "-2");
31 parse_special(empty, N) ->
32 list_to_integer(N).
33
34 parse_int(empty, "-ERR " ++ Message) ->
35 {error, Message};
36 parse_int(empty, Value) ->
37 list_to_integer(Value).
38
39 parse_string(empty, Message) ->
40 Message.
41
42 parse_types(empty, "none") -> none;
43 parse_types(empty, "string") -> string;
44 parse_types(empty, "list") -> list;
45 parse_types(empty, "set") -> set.
46
47
48 % I'm used when redis returns multiple results
49 stateful_parser(empty, "nil") ->
50 nil;
51 stateful_parser(error, "-ERR " ++ Error) ->
52 {error, Error};
53 stateful_parser(empty, "-" ++ _ErrorLength) ->
54 error;
55 stateful_parser(empty, NumberOfElements) ->
56 {hold, list_to_integer(NumberOfElements)};
57 stateful_parser(read, ElementSize) ->
58 {read, list_to_integer(ElementSize)}.
59
60 % I'm used when redis returns just one result
61 single_stateful_parser(empty, "nil") ->
62 nil;
63 single_stateful_parser(error, "-ERR " ++ Error) ->
64 {error, Error};
65 single_stateful_parser(empty, "-" ++ _ErrorLength) ->
66 error;
67 single_stateful_parser(empty, ElementSize) ->
68 {read, list_to_integer(ElementSize)}.