Commits

Jacob Perkins  committed 48dcd1c

erldis 0.1.6, keys returns a list, tests do not flushdb

  • Participants
  • Parent commits b91a6e0

Comments (0)

Files changed (5)

File ebin/erldis.app

 {application, erldis, [
 	{description, "Erlang Redis application"},
-	{vsn, "0.1.5"},
+	{vsn, "0.1.6"},
 	{registered, [erldis_sup]},
 	{mod, {erldis_app, []}},
 	{applications, [kernel, stdlib]},

File ebin/erldis.appup

-{"0.1.5", [
+{"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}]},
 		{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}]},

File src/erldis.erl

 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));

File test/erldis_pipelining_tests.erl

 
 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!">>),

File test/erldis_tests.erl

 
 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">>),