Permalink
Browse files

Type cleanup.

  • Loading branch information...
1 parent 7e1d75f commit eeab225b5cfb10a6a06d31ea1fe5a7c4fe6de3e0 Knut Nesheim committed Sep 30, 2011
Showing with 36 additions and 32 deletions.
  1. +7 −1 include/eredis.hrl
  2. +20 −22 src/eredis.erl
  3. +7 −7 src/eredis_client.erl
  4. +2 −2 src/eredis_parser.erl
View
@@ -1,4 +1,9 @@
--define(NL, "\r\n").
+%% Public types
+
+-type option() :: {host, string()} | {port, integer()} | {database, string()} | {password, string()} | {reconnect_sleep, integer()}.
+-type server_args() :: [option()].
+
+-type return_value() :: binary() | [binary()].
%% Continuation data is whatever data returned by any of the parse
@@ -14,3 +19,4 @@
continuation_data :: continuation_data() | undefined
}).
+-define(NL, "\r\n").
View
@@ -25,20 +25,6 @@
%% PUBLIC API
%%
-%% -type Args = [Option].
-%% -type Option = {host, string()} | {port, integer()} | {database, string()} | {password, string()} | {reconnect_sleep, integer()}.
--spec start_link( Args :: list() ) -> {ok, Pid::pid()} | {error, Reason::term()}.
-start_link(Args) ->
- Host = proplists:get_value(host, Args, "127.0.0.1"),
- Port = proplists:get_value(port, Args, 6379),
- Database = proplists:get_value(database, Args, 0),
- Password = proplists:get_value(password, Args, ""),
- ReconnectSleep = proplists:get_value(reconnect_sleep, Args, 100),
- eredis_client:start_link(Host, Port, Database, Password, ReconnectSleep).
-
-
--spec start_link() -> {ok, Client::pid()} |
- {error, {connection_error, Reason::any()}}.
start_link() ->
start_link("127.0.0.1", 6379, 0, "").
@@ -49,17 +35,30 @@ start_link(Host, Port, Database) ->
start_link(Host, Port, Database, "").
start_link(Host, Port, Database, Password) ->
- start_link(Host, Port, Database, Password, 100).
+ start_link(Host, Port, Database, Password, 100).
+
+start_link(Host, Port, Database, Password, ReconnectSleep)
+ when is_list(Host);
+ is_integer(Port);
+ is_integer(Database);
+ is_list(Password);
+ is_integer(ReconnectSleep) ->
-start_link(Host, Port, Database, Password, ReconnectSleep) when is_list(Host);
- is_integer(Port);
- is_integer(Database);
- is_list(Password);
- is_integer(ReconnectSleep)->
eredis_client:start_link(Host, Port, Database, Password, ReconnectSleep).
+%% @doc: Callback for starting from poolboy
+-spec start_link(server_args()) -> {ok, Pid::pid()} | {error, Reason::term()}.
+start_link(Args) ->
+ Host = proplists:get_value(host, Args, "127.0.0.1"),
+ Port = proplists:get_value(port, Args, 6379),
+ Database = proplists:get_value(database, Args, 0),
+ Password = proplists:get_value(password, Args, ""),
+ ReconnectSleep = proplists:get_value(reconnect_sleep, Args, 100),
+ start_link(Host, Port, Database, Password, ReconnectSleep).
+
+
-spec q(Client::pid(), Command::iolist()) ->
- {ok, Value::binary()} | {error, Reason::binary()}.
+ {ok, return_value()} | {error, Reason::binary()}.
%% @doc: Executes the given command in the specified connection. The
%% command must be a valid Redis command and may contain arbitrary
%% data which will be converted to binaries. The returned values will
@@ -100,4 +99,3 @@ to_binary(X) when is_binary(X) -> X;
to_binary(X) when is_integer(X) -> list_to_binary(integer_to_list(X));
to_binary(X) when is_float(X) -> throw({cannot_store_floats, X});
to_binary(X) -> term_to_binary(X).
-
View
@@ -25,7 +25,7 @@
-include("eredis.hrl").
%% API
--export([start_link/4, start_link/5, stop/1, select_database/2]).
+-export([start_link/5, stop/1, select_database/2]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
@@ -48,13 +48,13 @@
%%
%% API
%%
--spec start_link(Host::list(), Port::integer(), Database::integer(),
- Password::string()) -> {ok, Pid::pid()} | {error, Reason::term()}.
-start_link(Host, Port, Database, Password) ->
- start_link(Host, Port, Database, Password, 100).
--spec start_link(Host::list(), Port::integer(), Database::integer(),
- Password::string(), ReconnectSleep::integer()) -> {ok, Pid::pid()} | {error, Reason::term()}.
+-spec start_link(Host::list(),
+ Port::integer(),
+ Database::integer(),
+ Password::string(),
+ ReconnectSleep::integer()) ->
+ {ok, Pid::pid()} | {error, Reason::term()}.
start_link(Host, Port, Database, Password, ReconnectSleep) ->
gen_server:start_link(?MODULE, [Host, Port, Database, Password, ReconnectSleep], []).
View
@@ -43,8 +43,8 @@ init() ->
-spec parse(State::#pstate{}, Data::binary()) ->
- {ok, Value::binary(), NewState::#pstate{}} |
- {ok, Value::binary(), Rest::binary(), NewState::#pstate{}} |
+ {ok, return_value(), NewState::#pstate{}} |
+ {ok, return_value(), Rest::binary(), NewState::#pstate{}} |
{error, ErrString::binary(), NewState::#pstate{}} |
{error, ErrString::binary(), Rest::binary(), NewState::#pstate{}} |
{continue, NewState::#pstate{}}.

0 comments on commit eeab225

Please sign in to comment.