Permalink
Browse files

still useless but now behaviour compliant

  • Loading branch information...
1 parent 420b648 commit ccde754c54c19994fad12eabc083b2548bba06e5 Fernando 'Brujo' Benavides committed Nov 30, 2011
Showing with 82 additions and 79 deletions.
  1. +82 −79 test/benchmarks/erldis_hashes_bench.erl
@@ -16,10 +16,10 @@
-include("edis.hrl").
-export([all/0,
- init/0, init_per_testcase/1, init_per_round/2,
- quit/0, quit_per_testcase/1, quit_per_round/2]).
--export([hdel/1, hexists/1, hget/1, hgetall/1, hincrby/1, hkeys/1, hlen/1, hmget/1, hmset/1,
- hset/1, hsetnx/1, hvals/1]).
+ init/1, init_per_testcase/2, init_per_round/3,
+ quit/1, quit_per_testcase/2, quit_per_round/3]).
+-export([hdel/2, hexists/2, hget/2, hgetall/2, hincrby/2, hkeys/2, hlen/2, hmget/2, hmset/2,
+ hset/2, hsetnx/2, hvals/2]).
%% ====================================================================
%% External functions
@@ -28,127 +28,128 @@
all() -> [Fun || {Fun, _} <- ?MODULE:module_info(exports) -- edis_bench:behaviour_info(callbacks),
Fun =/= module_info].
--spec init() -> ok.
-init() -> ok.
-
--spec quit() -> ok.
-quit() -> ok.
+-spec init([pos_integer()]) -> ok.
+init([Port]) ->
+ case erldis:connect(localhost,16380) of
+ {ok, Client} ->
+ Name = process(Port),
+ case erlang:whereis(Name) of
+ undefined -> true;
+ _ -> erlang:unregister(Name)
+ end,
+ erlang:register(Name, Client);
+ Error -> throw(Error)
+ end.
+
+-spec quit([pos_integer()]) -> ok.
+quit([Port]) ->
+ Name = process(Port),
+ case erlang:whereis(Name) of
+ undefined -> true;
+ Client ->
+ erldis_client:stop(Client),
+ erlang:unregister(Name)
+ end,
+ ok.
--spec init_per_testcase(atom()) -> ok.
-init_per_testcase(_Function) -> ok.
+-spec init_per_testcase(atom(), [pos_integer()]) -> ok.
+init_per_testcase(_Function, _Extra) -> ok.
--spec quit_per_testcase(atom()) -> ok.
-quit_per_testcase(_Function) -> ok.
+-spec quit_per_testcase(atom(), [pos_integer()]) -> ok.
+quit_per_testcase(_Function, _Extra) -> ok.
--spec init_per_round(atom(), [binary()]) -> ok.
-init_per_round(incrby, Keys) ->
- _ = edis_db:run(
- edis_db:process(0),
- #edis_command{cmd = <<"HSET">>,
- args = [?KEY, ?KEY, edis_util:integer_to_binary(length(Keys))],
- result_type = boolean, group = hashes}),
- ok;
-init_per_round(Fun, Keys) when Fun =:= hgetall;
- Fun =:= hkeys;
- Fun =:= hvals;
- Fun =:= hlen ->
- _ =
- edis_db:run(
- edis_db:process(0),
- #edis_command{cmd = <<"HMSET">>, args = [?KEY, [{Key, <<"x">>} || Key <- Keys]],
- group = hashes, result_type = ok}),
+-spec init_per_round(atom(), [binary()], [pos_integer()]) -> ok.
+init_per_round(incrby, Keys, [Port]) ->
+ _ = erldis:hset(process(Port), ?KEY, ?KEY, edis_util:integer_to_binary(length(Keys))),
ok;
-init_per_round(Fun, _Keys) when Fun =:= hmget;
- Fun =:= hmset ->
- _ =
- edis_db:run(
- edis_db:process(0),
- #edis_command{cmd = <<"HMSET">>,
- args = [?KEY,
- [{edis_util:integer_to_binary(Key), <<"x">>} || Key <- lists:seq(1, 5000)]],
- group = hashes, result_type = ok}),
- ok;
-init_per_round(_Fun, Keys) ->
- _ =
- edis_db:run(
- edis_db:process(0),
- #edis_command{cmd = <<"HMSET">>, args = [?KEY, [{Key, <<"x">>} || Key <- Keys] ++
- [{<<Key/binary, "-2">>, <<"y">>} || Key <- Keys]],
- group = hashes, result_type = ok}),
+init_per_round(Fun, Keys, [Port]) when Fun =:= hgetall;
+ Fun =:= hkeys;
+ Fun =:= hvals;
+ Fun =:= hlen ->
+ erldis:hmset(process(Port), ?KEY, lists:flatmap(fun(Key) -> [Key, <<"x">>] end, Keys));
+init_per_round(Fun, _Keys, [Port]) when Fun =:= hmget; Fun =:= hmset ->
+ erldis:hmset(process(Port),
+ ?KEY,
+ lists:flatmap(
+ fun(Key) -> [edis_util:integer_to_binary(Key), <<"x">>] end,
+ lists:seq(1, 5000)));
+init_per_round(_Fun, Keys, [Port]) ->
+ erldis:hmset(process(Port),
+ ?KEY,
+ lists:flatmap(
+ fun(Key) -> [Key, <<"x">>, <<Key/binary, "-2">>, <<"y">>] end,
+ Keys)).
+
+-spec quit_per_round(atom(), [binary()], [pos_integer()]) -> ok.
+quit_per_round(_, _Keys, [Port]) ->
+ _ = erldis:del(process(Port), ?KEY),
ok.
--spec quit_per_round(atom(), [binary()]) -> ok.
-quit_per_round(_, _Keys) ->
- _ = edis_db:run(
- edis_db:process(0),
- #edis_command{cmd = <<"DEL">>, args = [?KEY], group = keys, result_type = number}
- ),
- ok.
--spec hdel([binary()]) -> pos_integer().
-hdel(Keys) ->
+-spec hdel([binary()], pos_integer()) -> pos_integer().
+hdel(Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HDEL">>, args = [?KEY | Keys], group = hashes, result_type = number}).
--spec hexists([binary(),...]) -> boolean().
-hexists([Key|_]) ->
+-spec hexists([binary(),...], pos_integer()) -> boolean().
+hexists([Key|_], Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HEXISTS">>, args = [?KEY, Key], result_type = boolean, group = hashes}).
--spec hget([binary()]) -> binary().
-hget([Key|_]) ->
+-spec hget([binary()], pos_integer()) -> binary().
+hget([Key|_], Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HGET">>, args = [?KEY, Key], result_type = bulk, group = hashes}).
--spec hgetall([binary()]) -> binary().
-hgetall(_Keys) ->
+-spec hgetall([binary()], pos_integer()) -> binary().
+hgetall(_Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HGETALL">>, args = [?KEY], result_type = multi_bulk, group = hashes}).
--spec hincrby([binary()]) -> integer().
-hincrby(Keys) ->
+-spec hincrby([binary()], pos_integer()) -> integer().
+hincrby(Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HINCRBY">>, args = [?KEY, ?KEY, length(Keys)],
group = hashes, result_type = number}).
--spec hkeys([binary()]) -> binary().
-hkeys(_Keys) ->
+-spec hkeys([binary()], pos_integer()) -> binary().
+hkeys(_Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HKEYS">>, args = [?KEY], result_type = multi_bulk, group = hashes}).
--spec hlen([binary()]) -> binary().
-hlen(_Keys) ->
+-spec hlen([binary()], pos_integer()) -> binary().
+hlen(_Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HLEN">>, args = [?KEY], result_type = number, group = hashes}).
--spec hmget([binary()]) -> binary().
-hmget(Keys) ->
+-spec hmget([binary()], pos_integer()) -> binary().
+hmget(Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HMGET">>, args = [?KEY | Keys], result_type = multi_bulk, group = hashes}).
--spec hmset([binary()]) -> binary().
-hmset(Keys) ->
+-spec hmset([binary()], pos_integer()) -> binary().
+hmset(Keys, Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HMSET">>, args = [?KEY, [{Key, <<"y">>} || Key <- Keys]],
result_type = ok, group = hashes}).
--spec hset([binary()]) -> binary().
-hset([Key|_]) ->
+-spec hset([binary()], pos_integer()) -> binary().
+hset([Key|_], Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HSET">>, args = [?KEY, Key, Key], result_type = boolean, group = hashes}).
--spec hsetnx([binary()]) -> binary().
-hsetnx([Key|_]) ->
+-spec hsetnx([binary()], pos_integer()) -> binary().
+hsetnx([Key|_], Port) ->
edis_db:run(
edis_db:process(0),
#edis_command{cmd = <<"HSETNX">>, args = [?KEY,
@@ -157,8 +158,10 @@ hsetnx([Key|_]) ->
2 -> <<Key/binary, "__">>
end, Key], result_type = boolean, group = hashes}).
--spec hvals([binary()]) -> binary().
-hvals(_Keys) ->
+-spec hvals([binary()], pos_integer()) -> binary().
+hvals(_Keys, Port) ->
edis_db:run(
edis_db:process(0),
- #edis_command{cmd = <<"HVALS">>, args = [?KEY], result_type = multi_bulk, group = hashes}).
+ #edis_command{cmd = <<"HVALS">>, args = [?KEY], result_type = multi_bulk, group = hashes}).
+
+process(Port) -> list_to_atom("erldis-tester-" ++ integer_to_list(Port)).

0 comments on commit ccde754

Please sign in to comment.