Get the App
SLTechnology News&Howtos  ›  Database  › 

Example of using redis database to store user information

Shulou Source: shulou.com Published: 2022-05-31 23:32:57 09月28日 Update

This article shares with you an example of using a redis database to store user information. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The recommended way is to use the hash type in the redis database to store.

Of course, it is OK to use session, but there will be drawbacks. If there is only one server, session is used, and when multiple servers are load balanced, session may be stored in A server, and when it is picked up, it will be on B server, so Redis is used.

Examples are as follows:

When a user changes personal information, it is stored in Redis + put into the database, which also caches the data and does not need to be queried again in the database.

Get information

(learn video sharing: redis video tutorial)

Service layer

Test it with postman!

Register the user first, and then query directly after the registration is successful.

Query the information according to the user Id

In this way, every query does not have to go through the database. If the user updates his personal information, it will be synchronized to redis.

Here the null value of phone and time is because I didn't forget to store it in redis when I registered, so there is a null value, one is registration, the other is change, just store the change in redis.

Thank you for reading! This is the end of this article on "examples of using redis database to store user information". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Data information database user storage server service query example personal content more article video good practical balanced success example again Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Docker macOS Shulou Information Shulou Tech Info