Skip to content

Commit

Permalink
Update to 0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
cstar committed Feb 5, 2010
1 parent 8eab955 commit b24ad76
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ebin/erldis.app
@@ -1,6 +1,6 @@
{application, erldis, [
{description, "Erlang Redis application"},
{vsn, "0.1.3"},
{vsn, "0.1.6"},
{registered, [erldis_sup]},
{mod, {erldis_app, []}},
{applications, [kernel, stdlib]},
Expand Down
8 changes: 7 additions & 1 deletion ebin/erldis.appup
@@ -1,4 +1,7 @@
{"0.1.3", [
{"0.1.6", [
{"0.1.5", [{load_module, erldis}]},
{"0.1.4", [{load_module, erldis_client}]},
{"0.1.3", [{load_module, erldis_client}]},
{"0.1.2", [{load_module, erldis_client}]},
{"0.1.1", [
{load_module, erldis},
Expand Down Expand Up @@ -56,6 +59,9 @@
{add_module, erldis_sets}
]}
], [
{"0.1.5", [{load_module, erldis}]},
{"0.1.4", [{load_module, erldis_client}]},
{"0.1.3", [{load_module, erldis_client}]},
{"0.1.2", [{load_module, erldis_client}]},
{"0.1.1", [
{load_module, erldis},
Expand Down
7 changes: 6 additions & 1 deletion src/erldis.erl
Expand Up @@ -91,7 +91,12 @@ type(Client, Key) ->
keys(Client, Pattern) when not is_binary(Pattern) ->
keys(Client, erldis_client:bin(Pattern));
keys(Client, Pattern) ->
erldis_client:scall(Client, <<"keys ", Pattern/binary>>).
% TODO: tokenize the binary directly (if is faster)
% NOTE: with binary-list conversion, timer:tc says 26000-30000 microseconds
case erldis_client:scall(Client, <<"keys ">>, [Pattern]) of
[] -> [];
[B] -> [list_to_binary(S) || S <- string:tokens(binary_to_list(B), " ")]
end.

randomkey(Client, Key) when not is_binary(Key) ->
randomkey(Client, erldis_client:bin(Key));
Expand Down
20 changes: 12 additions & 8 deletions src/erldis_client.erl
Expand Up @@ -103,6 +103,7 @@ sr_scall(Client, Cmd) -> sr_scall(Client, Cmd, []).
sr_scall(Client, Cmd, Args) ->
case scall(Client, Cmd, Args) of
[R] -> R;
[] -> nil;
ok -> ok
end.

Expand Down Expand Up @@ -313,8 +314,8 @@ connect_socket(State, _) ->
%% handle_call %%
%%%%%%%%%%%%%%%%%

handle_call(is_pipelined, _From, #redis{pipeline=P}=State)->
{reply, P, State};
handle_call(is_pipelined, _From, State)->
{reply, State#redis.pipeline, State};
handle_call(get_all_results, From, #redis{pipeline=true, calls=Calls} = State) ->
case queue:len(Calls) of
0 ->
Expand Down Expand Up @@ -395,7 +396,7 @@ send_reply(#redis{pipeline=true, calls=Calls, results=Results, reply_caller=Repl
R -> R
end,

{{value, _From}, Queue} = queue:out(Calls),
{_, Queue} = queue:out(Calls),

case queue:len(Queue) of
0 ->
Expand All @@ -417,12 +418,16 @@ send_reply(#redis{pipeline=true, calls=Calls, results=Results, reply_caller=Repl
end;

send_reply(State) ->
{{value, From}, Queue} = queue:out(State#redis.calls),
Reply = lists:reverse(State#redis.buffer),
gen_server2:reply(From, Reply),
case queue:out(State#redis.calls) of
{{value, From}, Queue} ->
Reply = lists:reverse(State#redis.buffer),
gen_server2:reply(From, Reply);
{empty, Queue} ->
ok
end,

State#redis{calls=Queue, buffer=[], pstate=empty}.


parse_state(State, Socket, Data) ->
Parse = erldis_proto:parse(State#redis.pstate, trim2(Data)),

Expand Down Expand Up @@ -470,7 +475,6 @@ handle_info({tcp, Socket, Data}, State) ->
{noreply, NewState}
end;
handle_info({tcp_closed, Socket}, State=#redis{socket=Socket}) ->
error_logger:warning_report([{erldis_client, tcp_closed}, State]),
{noreply, State#redis{socket=undefined}};
handle_info(_Info, State) ->
{noreply, State}.
Expand Down
2 changes: 1 addition & 1 deletion test/erldis_pipelining_tests.erl
Expand Up @@ -5,7 +5,7 @@

pipelining_test()->
{ok, Client} = erldis:connect("localhost", 6379),
erldis:flushall(Client),
?assertEqual(erldis:flushdb(Client), ok),
erldis:set_pipelining(Client, true),
erldis:get(Client, <<"pippo">>),
erldis:set(Client, <<"hello">>, <<"kitty!">>),
Expand Down
32 changes: 17 additions & 15 deletions test/erldis_tests.erl
Expand Up @@ -16,26 +16,28 @@ utils_test() ->

basic_test() ->
{ok, Client} = erldis:connect("localhost", 6379),
erldis:flushall(Client),
?assertEqual(erldis:flushdb(Client), ok),

nil = erldis:get(Client, <<"pippo">>),
?assertEqual(erldis:get(Client, <<"pippo">>), nil),
ok = erldis:set(Client, <<"hello">>, <<"kitty!">>),
true = erldis:setnx(Client, <<"foo">>, <<"bar">>),
false = erldis:setnx(Client, <<"foo">>, <<"bar">>),

true = erldis:exists(Client, <<"hello">>),
true = erldis:exists(Client, <<"foo">>),
<<"bar">> = erldis:get(Client, <<"foo">>),
[<<"kitty!">>, <<"bar">>] = erldis:mget(Client, [<<"hello">>, <<"foo">>]),
true = erldis:del(Client, <<"hello">>),
true = erldis:del(Client, <<"foo">>),
false = erldis:exists(Client, <<"hello">>),
false = erldis:exists(Client, <<"foo">>),
?assert(erldis:setnx(Client, <<"foo">>, <<"bar">>)),
?assertNot(erldis:setnx(Client, <<"foo">>, <<"bar">>)),

?assert(erldis:exists(Client, <<"hello">>)),
?assert(erldis:exists(Client, <<"foo">>)),
?assertEqual(erldis:get(Client, <<"foo">>), <<"bar">>),
?assertEqual(erldis:mget(Client, [<<"hello">>, <<"foo">>]), [<<"kitty!">>, <<"bar">>]),
?assertEqual(erldis:keys(Client, <<"f*">>), [<<"foo">>]),

?assert(erldis:del(Client, <<"hello">>)),
?assert(erldis:del(Client, <<"foo">>)),
?assertNot(erldis:exists(Client, <<"hello">>)),
?assertNot(erldis:exists(Client, <<"foo">>)),

erldis:sadd(Client, <<"set">>, <<"toto">>),
[<<"toto">>] = erldis:smembers(Client, <<"set">>),
?assertEqual(erldis:smembers(Client, <<"set">>), [<<"toto">>]),
erldis:srem(Client, <<"set">>, <<"toto">>),
[] = erldis:smembers(Client, <<"set">>).
?assertEqual(erldis:smembers(Client, <<"set">>), []).

%%% Commented out. Using the new erldis_set, erldis_list.
%ok = erldis:set(Client, <<"pippo">>, <<"pluto">>),
Expand Down

0 comments on commit b24ad76

Please sign in to comment.