title: Redis sorted set and solving ties
body: <p>I'm using a Redis sorted set to store a ranking for a project I'm working on.  We hadn't anticipated (!) how we wanted to handle ties. Redis sorts lexicographically the entries that have the same score, but what we want to do is instead give the same rank to all the entries that have the same score, so for instance in the case of</p>
  
  <pre><code>redis 127.0.0.1:6379&gt; ZREVRANGE foo 0 -1 WITHSCORES
  1) "first"
  2) "3"
  3) "second3"
  4) "2"
  5) "second2"
  6) "2"
  7) "second1"
  8) "2"
  9) "fifth"
  10) "1"
  </code></pre>
  
  <p>we want to consider <code>second1</code>, <code>second2</code> and <code>second3</code> as both having position 2, and <code>fifth</code> to have position 5.  Hence there is no entry in the third or fourth position.  <code>ZREVRANK</code> is not useful here, so what's the best way to get the number I'm looking for?</p>