Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the some basic modules; add redis_log hrl; add overview.doc; the …
…code compile and run ok
- Loading branch information
litao
committed
Mar 14, 2010
1 parent
19adea2
commit c23b5b9
Showing
9 changed files
with
263 additions
and
24 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,71 @@ | |||
%%%---------------------------------------------------------------------- | |||
%%% | |||
%%% @copyright erl-redis 2010 | |||
%%% | |||
%%% @author litaocheng@gmail.com | |||
%%% @doc the log header | |||
%%% | |||
%%%---------------------------------------------------------------------- | |||
-ifndef(REDIS_LOG_HRL). | |||
-define(REDIS_LOG_HRL, ok). | |||
|
|||
-ifdef(NOLOG). | |||
-define(DEBUG(F), ok). | |||
-define(DEBUG2(F, D), ok). | |||
|
|||
-define(INFO(F), ok). | |||
-define(INFO2(F, D), ok). | |||
|
|||
-define(WARN(F), ok). | |||
-define(WARN2(F, D), ok). | |||
|
|||
-define(ERROR(F), ok). | |||
-define(ERROR2(F, D), ok). | |||
|
|||
-else. | |||
|
|||
-ifdef(EUNIT). | |||
|
|||
-define(EUNITFMT(T, F, D), (?debugFmt((T) ++ "(~p) " ++ (F), [self()] ++ (D)))). | |||
|
|||
-define(DEBUG(F), ?EUNITFMT("[D]", F, [])). | |||
-define(DEBUG2(F, D), ?EUNITFMT("[D]", F, D)). | |||
|
|||
-define(INFO(F), ?EUNITFMT("[I]", F, [])). | |||
-define(INFO2(F, D), ?EUNITFMT("[I]", F, D)). | |||
|
|||
-define(WARN(F), ?EUNITFMT("[*W*]", F, [])). | |||
-define(WARN2(F, D), ?EUNITFMT("[*W*]", F, D)). | |||
|
|||
-define(ERROR(F), ?EUNITFMT("[**E**]", F, [])). | |||
-define(ERROR2(F, D), ?EUNITFMT("[**E**]", F, D)). | |||
|
|||
-else. | |||
-define(ML_FMT(F), " (~p:~p) "++(F)). | |||
-define(ML_DATA(D), [?MODLE, ?LINE]++(D)). | |||
|
|||
-define(DEBUG(F), | |||
error_logger:info_msg(?ML_FMT("[D]"++F), ?ML_DATA([])). | |||
-define(DEBUG2(F, D), | |||
error_logger:info_msg(?ML_FMT("[D]"++F), ?ML_DATA(D)). | |||
|
|||
-define(INFO(F), | |||
error_logger:info_msg(?ML_FMT("[I]"++F), ?ML_DATA([])). | |||
-define(INFO2(F, D), | |||
error_logger:info_msg(?ML_FMT("[I]"++F), ?ML_DATA(D)). | |||
|
|||
-define(WARN(F), | |||
error_logger:warning_msg(?ML_FMT("[*W*]"++F), ?ML_DATA([])). | |||
-define(WARN2(F, D), | |||
error_logger:warning_msg(?ML_FMT("[*W*]"++F), ?ML_DATA(D)). | |||
|
|||
-define(ERROR(F), | |||
error_logger:error_msg(?ML_FMT("[**E**]"++F), ?ML_DATA([])). | |||
-define(ERROR2(F, D), | |||
error_logger:error_msg(?ML_FMT("[**E**]"++F), ?ML_DATA(D)). | |||
|
|||
-endif. %EUNIT | |||
|
|||
-endif. %NOLOG | |||
|
|||
-endif. % REDIS_LOG_HRL |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
** this is the overview.doc file for the application 'erl-redis' ** | |||
|
|||
@author litaocheng <litaocheng@gmail.com> | |||
@copyright 2010 | |||
@version @VERSION@ | |||
@title Welcome to the `erl-redis' application! | |||
@doc `erl-redis' is an erlang client for redis. |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
%%%---------------------------------------------------------------------- | |||
%%% | |||
%%% @copyright erl-redis 2010 | |||
%%% | |||
%%% @author litaocheng@gmail.com | |||
%%% @doc the interface for redis | |||
%%% @end | |||
%%% | |||
%%%---------------------------------------------------------------------- | |||
-module(redis). | |||
-author('ltiaocheng@gmail.com'). | |||
-vsn('0.1'). | |||
-include("redis.hrl"). | |||
|
|||
-export([i/0]). | |||
|
|||
|
|||
%% @doc show stats info in the stdout | |||
-spec i() -> 'ok'. | |||
i() -> | |||
ok. |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,52 @@ | |||
%%%---------------------------------------------------------------------- | |||
%%% | |||
%%% @copyright erl-redis 2010 | |||
%%% | |||
%%% @author litao cheng <litaocheng@gmail.com> | |||
%%% @doc redis app and supervisor callback | |||
%%% @end | |||
%%% | |||
%%%---------------------------------------------------------------------- | |||
-module(redis_app). | |||
-author('litaocheng@gmail.com'). | |||
-vsn('0.1'). | |||
-include("redis.hrl"). | |||
|
|||
-behaviour(application). | |||
-behaviour(supervisor). | |||
|
|||
-export([start/0]). | |||
-export([start/2, stop/1]). | |||
-export([init/1]). | |||
|
|||
-define(MAIN_SUP, redis_sup). | |||
|
|||
%% @doc start the application from the erl shell | |||
-spec start() -> 'ok' | {'error', any()}. | |||
start() -> | |||
?DEBUG2("start the ~p application", [?MODULE]), | |||
application:start(redis). | |||
|
|||
%% @doc the application start callback | |||
-spec start(Type :: any(), Args :: any()) -> any(). | |||
start(_Type, _Args) -> | |||
?INFO2("start the supervisor sup", []), | |||
supervisor:start_link({local, ?MAIN_SUP}, ?MODULE, []). | |||
|
|||
%% @doc the application stop callback | |||
stop(_State) -> | |||
ok. | |||
|
|||
%% @doc supervisor callback | |||
init(_Args) -> | |||
?DEBUG2("init supervisor~n", []), | |||
Stragegy = {simple_one_for_one, 10, 10}, | |||
Client = {undefined, {redis_client, start_link, []}, | |||
permanent, 1000, worker, [redis_client]}, | |||
|
|||
{ok, {Stragegy, [Client]}}. | |||
|
|||
%% | |||
%% internal API | |||
%% | |||
|
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
%%%---------------------------------------------------------------------- | |||
%%% | |||
%%% @copyright erl-redis 2010 | |||
%%% | |||
%%% @author litaocheng <litaocheng@gmail.com> | |||
%%% @doc | |||
%%% @end | |||
%%% | |||
%%%---------------------------------------------------------------------- | |||
-module(redis_client). | |||
-author('litaocheng@gmail.com'). | |||
-vsn('0.1'). | |||
-behaviour(gen_server). | |||
-include("redis.hrl"). | |||
|
|||
-export([start/0, start_link/0]). | |||
|
|||
|
|||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, | |||
terminate/2, code_change/3]). | |||
|
|||
-record(state, { | |||
}). | |||
|
|||
-define(SERVER, ?MODULE). | |||
|
|||
%% @doc start the redis_sysdata server | |||
-spec start() -> {'ok', any()} | 'ignore' | {'error', any()}. | |||
start() -> | |||
?DEBUG2("start ~p ~n", [?SERVER]), | |||
gen_server:start({local, ?SERVER}, ?MODULE, [], []). | |||
|
|||
%% @doc start_link the redis_sysdata server | |||
-spec start_link() -> {'ok', any()} | 'ignore' | {'error', any()}. | |||
start_link() -> | |||
?DEBUG2("start_link ~p ~n", [?SERVER]), | |||
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). | |||
|
|||
%% | |||
%% gen_server callbacks | |||
%% | |||
init(_Args) -> | |||
{ok, #state{}}. | |||
|
|||
handle_call(_Msg, _From, State) -> | |||
{noreply, State}. | |||
|
|||
handle_cast(_Msg, State) -> | |||
{noreply, State}. | |||
|
|||
handle_info(_Info, State) -> | |||
{noreply, State}. | |||
|
|||
terminate(_Reason, _State) -> | |||
ok. | |||
|
|||
code_change(_Old, State, _Extra) -> | |||
{ok, State}. | |||
|
|||
%%----------------------------------------------------------------------------- | |||
%% | |||
%% internal API | |||
%% | |||
%%----------------------------------------------------------------------------- | |||
|
|||
-ifdef(TEST). | |||
|
|||
-endif. |