Permalink
Browse files

Added zrank and zrevrank methods and tests.

  • Loading branch information...
1 parent 7ea2b21 commit 135581114443173e2eeded5af66ac1400dba73d6 @czarneckid czarneckid committed Mar 16, 2011
Showing with 11 additions and 2 deletions.
  1. +1 −1 .gitignore
  2. +5 −1 src/erldis.erl
  3. +5 −0 test/erldis_tests.erl
View
@@ -1,4 +1,4 @@
ebin/*
*.beam
deps/*
-
+.eunit/*
View
@@ -185,7 +185,11 @@ zrem(Client, Key, Member) ->
zincrby(Client, Key, By, Member) ->
numeric(erldis_client:sr_scall(Client, [<<"zincrby">>, Key, By, Member])).
-%% TODO: zrank, zrevrank
+zrank(Client, Key, Member) ->
+ numeric(erldis_client:sr_scall(Client, [<<"zrank">>, Key, Member])).
+
+zrevrank(Client, Key, Member) ->
+ numeric(erldis_client:sr_scall(Client, [<<"zrevrank">>, Key, Member])).
zrange(Client, Key, Start, End) ->
erldis_client:scall(Client, [<<"zrange">>, Key, Start, End]).
View
@@ -110,6 +110,7 @@ zset_test() ->
?assertEqual(0, erldis:zcount(Client, <<"foo">>, 0, 10)),
?assertEqual([], erldis:zrange(Client, <<"foo">>, 0, 1)),
?assertEqual(0, erldis:zscore(Client, <<"foo">>, <<"elem1">>)),
+ ?assertEqual(0, erldis:zrank(Client, <<"foo">>, <<"elem1">>)),
?assertEqual(true, erldis:zadd(Client, <<"foo">>, 5, <<"elem1">>)),
?assertEqual([<<"elem1">>], erldis:zrange(Client, <<"foo">>, 0, 1)),
@@ -128,6 +129,10 @@ zset_test() ->
?assertEqual(1, erldis:zcount(Client, <<"foo">>, 0, 2)),
?assertEqual(2, erldis:zcount(Client, <<"foo">>, 0, 10)),
?assertEqual(1.5, erldis:zscore(Client, "foo", "a-elem")),
+ ?assertEqual(1, erldis:zrank(Client, <<"foo">>, <<"elem1">>)),
+ ?assertEqual(0, erldis:zrank(Client, <<"foo">>, <<"a-elem">>)),
+ ?assertEqual(0, erldis:zrevrank(Client, <<"foo">>, <<"elem1">>)),
+ ?assertEqual(1, erldis:zrevrank(Client, <<"foo">>, <<"a-elem">>)),
?assertEqual([<<"a-elem">>, <<"elem1">>], erldis:zrange(Client, "foo", 0, 2)),
?assertEqual([<<"elem1">>, <<"a-elem">>], erldis:zrevrange(Client, "foo", 0, 2)),
?assertEqual([{<<"a-elem">>, 1.5}, {<<"elem1">>, 8}], erldis:zrange_withscores(Client, "foo", 0, 2)),

0 comments on commit 1355811

Please sign in to comment.