Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Erlang client synched with Valentiono's repo
- Loading branch information
Showing
7 changed files
with
89 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
repo: 9e1f35ed7fdc7b3da7f5ff66a71d1975b85e2ae5 | ||
node: 7f98e864d76b0b2a7427049b943fb1c0dad0df2a | ||
node: d9dd3d00c6fafaa09809061816f4e3b85a32811d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
-record(redis, {socket,buffer=[],reply_caller,parsers,remaining=0,pstate=empty,results=[]}). | ||
-record(redis, {socket,buffer=[],reply_caller,calls=0,remaining=0,pstate=empty,results=[]}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,38 @@ | ||
-module(proto). | ||
|
||
-export([parse/2, parse_int/2, parse_types/2, | ||
parse_string/2, stateful_parser/2, | ||
single_stateful_parser/2, parse_special/2]). | ||
|
||
-export([parse/2]). | ||
|
||
parse(empty, "+OK") -> | ||
ok; | ||
parse(empty, "+PONG") -> | ||
pong; | ||
parse(empty, "0") -> | ||
parse(empty, ":0") -> | ||
false; | ||
parse(empty, "1") -> | ||
parse(empty, ":1") -> | ||
true; | ||
parse(empty, "-1") -> | ||
{error, no_such_key}; | ||
parse(empty, "-2") -> | ||
{error, wrong_type}; | ||
parse(empty, "-3") -> | ||
{error, same_db}; | ||
parse(empty, "-4") -> | ||
{error, argument_out_of_range}; | ||
parse(empty, "-" ++ Message) -> | ||
{error, Message}. | ||
|
||
parse_special(empty, "-1") -> | ||
parse(empty, "-1"); | ||
parse_special(empty, "-2") -> | ||
parse(empty, "-2"); | ||
parse_special(empty, N) -> | ||
list_to_integer(N). | ||
|
||
parse_int(empty, "-ERR " ++ Message) -> | ||
{error, Message}; | ||
parse_int(empty, Value) -> | ||
list_to_integer(Value). | ||
|
||
parse_string(empty, Message) -> | ||
parse(empty, "$-1") -> | ||
{read, nil}; | ||
parse(empty, "*-1") -> | ||
{hold, nil}; | ||
parse(empty, "$" ++ BulkSize) -> | ||
{read, list_to_integer(BulkSize)}; | ||
parse(read, "$" ++ BulkSize) -> | ||
{read, list_to_integer(BulkSize)}; | ||
parse(empty, "*" ++ MultiBulkSize) -> | ||
{hold, list_to_integer(MultiBulkSize)}; | ||
parse(empty, Message) -> | ||
convert(Message). | ||
|
||
convert(":" ++ Message) -> | ||
list_to_integer(Message); | ||
% in case the message is not OK or PONG it's a | ||
% real value that we don't know how to convert | ||
% to an atom, so just pass it as is and remove | ||
% the + | ||
convert("+" ++ Message) -> | ||
Message; | ||
convert(Message) -> | ||
Message. | ||
|
||
parse_types(empty, "none") -> none; | ||
parse_types(empty, "string") -> string; | ||
parse_types(empty, "list") -> list; | ||
parse_types(empty, "set") -> set. | ||
|
||
|
||
% I'm used when redis returns multiple results | ||
stateful_parser(empty, "nil") -> | ||
nil; | ||
stateful_parser(error, "-ERR " ++ Error) -> | ||
{error, Error}; | ||
stateful_parser(empty, "-" ++ _ErrorLength) -> | ||
error; | ||
stateful_parser(empty, NumberOfElements) -> | ||
{hold, list_to_integer(NumberOfElements)}; | ||
stateful_parser(read, ElementSize) -> | ||
{read, list_to_integer(ElementSize)}. | ||
|
||
% I'm used when redis returns just one result | ||
single_stateful_parser(empty, "nil") -> | ||
nil; | ||
single_stateful_parser(error, "-ERR " ++ Error) -> | ||
{error, Error}; | ||
single_stateful_parser(empty, "-" ++ _ErrorLength) -> | ||
error; | ||
single_stateful_parser(empty, ElementSize) -> | ||
{read, list_to_integer(ElementSize)}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters