Home  >  Article  >  Database  >  Use redis database to store user information

Use redis database to store user information

王林
王林forward
2021-02-08 09:46:013642browse

Use redis database to store user information

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

Of course it is possible to use session, but there will be disadvantages. If there is only one server and use session, when multiple servers are load balanced, the session may be stored in server A and retrieved in server B, but cannot be retrieved. to, so use Redis.

The example is as follows:

Use redis database to store user information

When the user changes personal information, it is stored in Redis and put into the database. This will also cache the data and does not need to be in the database. Query again.

Use redis database to store user information

Get information

Use redis database to store user information

(Learning video sharing: redis video tutorial)

service layer

Use redis database to store user information

Test it with postman!
Register the user first, then query directly after successful registration

Use redis database to store user information

According to the user ID, query the information

Use redis database to store user information

This way There is no need to go through the database for every query. If the user updates personal information, it will be synchronized to redis
The null values ​​for phone and time here are because I did not forget to save them in redis when registering, so null values ​​appear. One is registration. , one is to change, just store the changes in redis.

Related recommendations: redis database tutorial

The above is the detailed content of Use redis database to store user information. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete