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:
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.
Get information
(Learning video sharing: redis video tutorial)
service layer
Test it with postman!
Register the user first, then query directly after successful registration
According to the user ID, query the 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!