cstar/erldis — pull request #11 by gchaincl (2012-04-13 17:15:08+00:00)
Title: concurrent mget bug for non existing keys

When you are calling mget with many spawned process some of them may not respond due a bug on erldis_client:parse_state/3. This patch resolve the problem.

If you want to reproduce the error try this:

-module(mytest).
-author('gustavo.chain@inakanetworks.com').
-vsn('').

-export([init/0]).
-export([mget/1, mget/3, cc_mget/2]).

-define(LINK, erldis_pool_sup:get_random_pid({"10.211.55.3",6379})).

init() ->
{ok, Pid} = erldis_pool_sup:start_link([{{"10.211.55.3", 6379}, 1}]),
Pid.

mget(List) ->
R = erldis:mget(?LINK, List),
io:format("~p: ~p\n", [self(), R]),
R.
mget(List, Pid, N) ->
try
%	io:format("Calling mget~n"),
mget(List),
%	io:format("Called mget~n"),
Pid ! {ok, N}
catch _:X ->
{error, X, erlang:get_stacktrace()}
end.

%cc_mget(List) ->
%	lists:foreach(fun(X) -> spawn(?MODULE, mget, [List, X]) end, lists:seq(1, N)).

cc_mget(0, _) ->
cc_mget_receive(0);
cc_mget(N, Keys) ->
spawn(?MODULE, mget, [Keys, self(), N]),
cc_mget(N - 1, Keys).

cc_mget_receive(N) ->
receive
{ok, _} ->
cc_mget_receive(N + 1)
after 3000 ->
io:format("Finish with ~p!~n", [N])
end.