title: Hashing an email (or username) to store in redis hash buckets
body: <p>I am writing a node.js application that relies on redis as its main database, and user info is stored in this database.</p>
  
  <p>I currently have the user data (email, password, date created, etc.) in a hash with the name as <code>user:(incremental uid)</code>. And a key <code>email:(email)</code> with value <code>(same incremental uid)</code>.</p>
  
  <p>When someone logs in, the app looks up a key matching the email with <code>email:(email)</code> to return the <code>(incremental uid)</code> to access the user data with <code>user:(incremental uid)</code>.</p>
  
  <p>This works great, however, if the number of users reaches into the millions (possible, but somewhat a distant issue), my database size will increase dramatically and I'll start running into some problems.</p>
  
  <p>I'm wondering how to hash an email down to an integer that I can use to sort into hash buckets like this (pseudocode):</p>
  
  <pre><code>hash(thisguy@somedomain.com) returns 1234  
  1234 % 3 or something returns 1
  store { thisguy@somedomain.com : (his incremental uid) } in hash emailbucket:1
  </code></pre>
  
  <p>Then when I need to lookup this uid for email <code>thisguy@somedomain.com</code>, I use a similar procedure:</p>
  
  <pre><code>hash(thisguy@somedomain.com) returns 1234  
  1234 % 3 or something returns 1
  lookup thisguy@somedomain.com in hash emailbucket:1 returns his (incremental uid)
  </code></pre>
  
  <p>So, my questions in list form:</p>
  
  <ol>
  <li>Is this practical / is there a better way?</li>
  <li>How can I hash the email to a few digits?</li>
  <li>What is the best way to organize these hashes into buckets?</li>
  </ol>