Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added zrank and zrevrank methods and tests.

  • Loading branch information...
commit 135581114443173e2eeded5af66ac1400dba73d6 1 parent 7ea2b21
David Czarnecki authored March 16, 2011
2  .gitignore
... ...
@@ -1,4 +1,4 @@
1 1
 ebin/*
2 2
 *.beam
3 3
 deps/*
4  
-
  4
+.eunit/*
6  src/erldis.erl
@@ -185,7 +185,11 @@ zrem(Client, Key, Member) ->
185 185
 zincrby(Client, Key, By, Member) ->
186 186
 	numeric(erldis_client:sr_scall(Client, [<<"zincrby">>, Key, By, Member])).
187 187
 
188  
-%% TODO: zrank, zrevrank
  188
+zrank(Client, Key, Member) ->
  189
+	numeric(erldis_client:sr_scall(Client, [<<"zrank">>, Key, Member])).
  190
+
  191
+zrevrank(Client, Key, Member) ->
  192
+	numeric(erldis_client:sr_scall(Client, [<<"zrevrank">>, Key, Member])).
189 193
 
190 194
 zrange(Client, Key, Start, End) ->
191 195
 	erldis_client:scall(Client, [<<"zrange">>, Key, Start, End]).
5  test/erldis_tests.erl
@@ -110,6 +110,7 @@ zset_test() ->
110 110
 	?assertEqual(0, erldis:zcount(Client, <<"foo">>, 0, 10)),
111 111
 	?assertEqual([], erldis:zrange(Client, <<"foo">>, 0, 1)),
112 112
 	?assertEqual(0, erldis:zscore(Client, <<"foo">>, <<"elem1">>)),
  113
+	?assertEqual(0, erldis:zrank(Client, <<"foo">>, <<"elem1">>)),
113 114
 	
114 115
 	?assertEqual(true, erldis:zadd(Client, <<"foo">>, 5, <<"elem1">>)),
115 116
 	?assertEqual([<<"elem1">>], erldis:zrange(Client, <<"foo">>, 0, 1)),
@@ -128,6 +129,10 @@ zset_test() ->
128 129
 	?assertEqual(1, erldis:zcount(Client, <<"foo">>, 0, 2)),
129 130
 	?assertEqual(2, erldis:zcount(Client, <<"foo">>, 0, 10)),
130 131
 	?assertEqual(1.5, erldis:zscore(Client, "foo", "a-elem")),
  132
+	?assertEqual(1, erldis:zrank(Client, <<"foo">>, <<"elem1">>)),
  133
+	?assertEqual(0, erldis:zrank(Client, <<"foo">>, <<"a-elem">>)),
  134
+	?assertEqual(0, erldis:zrevrank(Client, <<"foo">>, <<"elem1">>)),
  135
+	?assertEqual(1, erldis:zrevrank(Client, <<"foo">>, <<"a-elem">>)),
131 136
 	?assertEqual([<<"a-elem">>, <<"elem1">>], erldis:zrange(Client, "foo", 0, 2)),
132 137
 	?assertEqual([<<"elem1">>, <<"a-elem">>], erldis:zrevrange(Client, "foo", 0, 2)),
133 138
 	?assertEqual([{<<"a-elem">>, 1.5}, {<<"elem1">>, 8}], erldis:zrange_withscores(Client, "foo", 0, 2)),

0 notes on commit 1355811

Please sign in to comment.
Something went wrong with that request. Please try again.