Skip to content

Commit

Permalink
Handle no_connection in eval/4
Browse files Browse the repository at this point in the history
Fixes #49
  • Loading branch information
bjosv committed Oct 14, 2020
1 parent c29efc4 commit 322b5a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/eredis_cluster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,10 @@ eval(Script, ScriptHash, Keys, Args) ->
case qk(EvalShaCommand, Key) of
{error, <<"NOSCRIPT", _/binary>>} ->
LoadCommand = ["SCRIPT", "LOAD", Script],
[_, Result] = qk([LoadCommand, EvalShaCommand], Key),
Result;
case qk([LoadCommand, EvalShaCommand], Key) of
[_LoadResult, EvalShaResult] -> EvalShaResult;
Result -> Result
end;
Result ->
Result
end.
Expand Down
4 changes: 3 additions & 1 deletion test/eredis_cluster_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ basic_test_() ->

{ "eval",
fun () ->
%% Remove scripts from a previous run to make sure we test the NOSCRIPT handling
?assertMatch([{ok, _},{ok, _},{ok, _}], eredis_cluster:qa(["SCRIPT", "FLUSH"])),
Script = <<"return redis.call('set', KEYS[1], ARGV[1]);">>,
ScriptHash = << << if N >= 10 -> N -10 + $a; true -> N + $0 end >> || <<N:4>> <= crypto:hash(sha, Script) >>,
eredis_cluster:eval(Script, ScriptHash, ["qrs"], ["evaltest"]),
?assertMatch({ok, _}, eredis_cluster:eval(Script, ScriptHash, ["qrs"], ["evaltest"])),
?assertEqual({ok, <<"evaltest">>}, eredis_cluster:q(["get", "qrs"]))
end
}
Expand Down

0 comments on commit 322b5a4

Please sign in to comment.