Like is a small module of the whole system, and the code is under user-service user service.
This article is based on SpringCloud. After users initiate likes and cancel likes, they are first stored in Redis, and then the like data is read from Redis and written to the database for persistent storage every two hours.
The like function is available in many systems, but despite the small function, there are quite a lot of things to consider if you want to do it well.
Upvoting and canceling likes are high-frequency operations. If the database is read and written every time, a large number of operations will affect the performance of the database, so caching is required.
As for how often to retrieve data from Redis and store it in the database, it depends on the actual situation of the project. I temporarily set it to two hours.
Project requirements need to check who has liked, so it is necessary to store the likes and likes of each like, and cannot simply count.
The article is divided into four parts:
Redis cache design and implementation
Enable the persistent storage of scheduled tasks to the database
1. Redis cache design and implementation
1.1 Redis installation and operation
Please refer to the relevant tutorials for Redis installation.
Let’s talk about Docker installation and running Redis
docker run -d -p 6379:6379 redis:4.0.8
If Redis has been installed, open the command line and enter the command to start Redis