Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MONITOR improved

  • Loading branch information...
commit 2cc59b5ab7f3e31a80a7091fa9f9e851ff2baeed 1 parent cfc6252
Fernando "Brujo" Benavides authored
View
16 src/edis_command_runner.erl
@@ -78,9 +78,11 @@ handle_cast({err, Message}, State) ->
tcp_err(Message, State);
handle_cast({run, Cmd, Args}, State) ->
try
- Command = parse_command(#edis_command{cmd = Cmd,
- db = State#state.db_index,
- args = Args}),
+ OriginalCommand = #edis_command{cmd = Cmd,
+ db = State#state.db_index,
+ args = Args},
+ Command = parse_command(OriginalCommand),
+ ok = edis_db_monitor:notify(OriginalCommand),
run(Command, State)
catch
_:unknown_command ->
@@ -133,14 +135,14 @@ handle_cast({run, Cmd, Args}, State) ->
%% @hidden
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
handle_info(#edis_command{db = 0} = Command, State) ->
- tcp_ok(io_lib:format("~p ~s ~p", [Command#edis_command.timestamp,
+ tcp_ok(io_lib:format("~p ~s ~s", [Command#edis_command.timestamp,
Command#edis_command.cmd,
- Command#edis_command.args]), State);
+ edis_util:join(Command#edis_command.args, <<" ">>)]), State);
handle_info(#edis_command{} = Command, State) ->
- tcp_ok(io_lib:format("~p (db ~p) ~s ~p", [Command#edis_command.timestamp,
+ tcp_ok(io_lib:format("~p (db ~p) ~s ~s", [Command#edis_command.timestamp,
Command#edis_command.db,
Command#edis_command.cmd,
- Command#edis_command.args]), State);
+ edis_util:join(Command#edis_command.args, <<" ">>)]), State);
handle_info({gen_event_EXIT, _Handler, Reason}, State) ->
?INFO("Monitor deactivated. Reason: ~p~n", [Reason]),
{noreply, State, hibernate};
View
1  src/edis_db.erl
@@ -2084,7 +2084,6 @@ make_call(Process, Request) ->
%% @private
make_call(Process, Request, Timeout) ->
?DEBUG("CALL for ~p: ~p~n", [Process, Request]),
- ok = edis_db_monitor:notify(Process, Request),
try gen_server:call(Process, Request, Timeout) of
ok -> ok;
{ok, Reply} -> Reply;
View
18 src/edis_db_monitor.erl
@@ -13,7 +13,7 @@
-behaviour(gen_event).
--export([start_link/0, add_sup_handler/0, delete_handler/0, notify/2]).
+-export([start_link/0, add_sup_handler/0, delete_handler/0, notify/1]).
-export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]).
-record(state, {client :: pid()}).
@@ -48,19 +48,9 @@ delete_handler() ->
gen_event:delete_handler(?MODULE, {?MODULE, self()}, normal).
%% @doc Notifies an event.
--spec notify(atom(), term()) -> ok.
-notify(DbProcess, Command) ->
- "edis-db-" ++ Index = atom_to_list(DbProcess),
- {Cmd, Args} =
- case Command of
- Command when is_atom(Command) -> {Command, []};
- Command ->
- [C|A] = tuple_to_list(Command),
- {C, A}
- end,
- gen_event:notify(?MODULE, #edis_command{db = list_to_integer(Index),
- cmd = Cmd,
- args = Args}).
+-spec notify(#edis_command{}) -> ok.
+notify(Command) ->
+ gen_event:notify(?MODULE, Command).
%% ====================================================================
%% Server functions
View
12 src/edis_util.erl
@@ -10,7 +10,7 @@
-author('Chad DePue <chad@inakanetworks.com>').
-export([timestamp/0, now/0, upper/1, lower/1, binary_to_integer/1, binary_to_integer/2,
- integer_to_binary/1, binary_to_float/1, make_pairs/1, glob_to_re/1]).
+ integer_to_binary/1, binary_to_float/1, make_pairs/1, glob_to_re/1, join/2]).
-include("elog.hrl").
@@ -107,4 +107,12 @@ glob_to_re(Pattern) ->
binary:replace(Pattern, <<"*">>, <<".*">>, [global]),
<<"?">>, <<".">>, [global]),
<<"(">>, <<"\\(">>, [global]),
- <<")">>, <<"\\)">>, [global]).
+ <<")">>, <<"\\)">>, [global]).
+
+-spec join([binary()], binary()) -> binary().
+join([], _) -> <<>>;
+join([Bin], _) -> Bin;
+join([Bin|Bins], Sep) -> join(Bins, Sep, Bin).
+
+join([], _, Acc) -> Acc;
+join([Bin|Bins], Sep, Acc) -> join(Bins, Sep, <<Acc/binary, Sep/binary, Bin/binary>>).
Please sign in to comment.
Something went wrong with that request. Please try again.