title: Redis sorted set based on score and date time as tie breaker?
body: <p>I would like to use a redis' sorted set as a leader board. But using <code>ZREVRANGE 0 x</code>, I can only get the top x from the score (the end of the score based ascending sorted set), with the default tie breaker which is, from the official redis documentation: </p>
  
  <blockquote>
    <p>Lexicographical order is used for elements with equal score.</p>
  </blockquote>
  
  <p>The tie breaker I would need is the date time of the score entry.</p>
  
  <p>e.g.</p>
  
  <pre><code>submits (in order)     redis sorts it as      I need
  User1 -- Score 50      User1                  User1
  User3 -- Score 40      User2                  User3
  User2 -- Score 40      User3                  User2
  </code></pre>
  
  <p>The only solution I see is to store the date time of the last update on the entry but still use <code>ZREVRANGE key 0 x</code> to get max and min scores from the the top x users. Then do a <code>ZREVRANGEBYSCORE key max min</code>. If the result length is higher than x, there is at least one tie so I would sort that smaller list in Lua using 2 keys.</p>
  
  <p>This method seems very slow and I need to make it work for hundreds of thousands of users. I don't like the 2 calls and processing with Lua (on the redis side, to stay atomic) and would like to know if there is a better way to use 2 keys for sorted sets or configure another tie breaker?</p>
  
  <p>My code is already written so I cannot change my type of database. If you have any interesting idea, I am interested to hear them, as I am not an expert about redis.</p>