I am writing a node.js application that relies on redis as its main database, and user info is stored in this database.
I currently have the user data (email, password, date created, etc.) in a hash with the name as user:(incremental uid)
. And a key email:(email)
with value (same incremental uid)
.
When someone logs in, the app looks up a key matching the email with email:(email)
to return the (incremental uid)
to access the user data with user:(incremental uid)
.
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.
I'm wondering how to hash an email down to an integer that I can use to sort into hash buckets like this (pseudocode):
hash([email protected]) returns 1234
1234 % 3 or something returns 1
store { [email protected] : (his incremental uid) } in hash emailbucket:1
Then when I need to lookup this uid for email [email protected]
, I use a similar procedure:
hash([email protected]) returns 1234
1234 % 3 or something returns 1
lookup [email protected] in hash emailbucket:1 returns his (incremental uid)
So, my questions in list form:
- Is this practical / is there a better way?
- How can I hash the email to a few digits?
- What is the best way to organize these hashes into buckets?
GET
andINCR
each time you add a new user.