Redis newbie - equivalent mysql table approach

I am new to Redis and was hoping for a "best practice" solution to implement the equivalent of the "users" table in the mysql database to handle users in a web application.

Would I create SET users in Redis? Or a user database with SET for each user?

+6
redis
source share
2 answers

My default setting for users is a serialized object in the standard u: userid key - this object gets access to each request, and access to only one of the properties is never required.

You can also use a hash rather than json for user properties, but my setup includes everything that is used as strongly typed objects and redis runs on a different server from the client, so using json simplifies the use of general deserialization and minimizes any delay problems .

In addition to the user object itself, you will need an index for any fields that you must use to search for the user - for example, to allow the user to log in with an email address, you will need the key e: email => User ID. The hash will also work here - the important thing is that you need something that is O (1) in order to receive from email to the user object.

Sometimes parts of user data must have their own keys - for example, a list of followers is ideal for redis, so it's best to store it in this form.

+8
source share

It really depends on what you want to do with users in your application. Another option is for each user to have their own hash, where they are properties (fields) for each user (firstName, lastName, etc.). You can use a key that you increase as an identifier generator for insertion, and a potentially different set that you use to store all user identifiers.

+1
source share

All Articles