How to process the app client at the code layer concurrent multiple requests concurrently with the individual?
There is an interface to share statistics, sometimes the client and the individual will be concurrent multiple requests come over, the server did the cluster, the first through Redis to do a cache (Uid+articleid) to determine whether there is, the results are directly bypassed.
Is there any way to directly judge in the code logic, and then return directly, rather than to MySQL there through a unique index what to solve.
Thank you ~~ ~
Reply content:
How to process the app client at the code layer concurrent multiple requests concurrently with the individual?
There is an interface to share statistics, sometimes the client and the individual will be concurrent multiple requests come over, the server did the cluster, the first through Redis to do a cache (Uid+articleid) to determine whether there is, the results are directly bypassed.
Is there any way to directly judge in the code logic, and then return directly, rather than to MySQL there through a unique index what to solve.
Thank you ~~ ~
Log this personal access interval, and return the error code directly if the frequency exceeds the limit value ~ ~
Requests from the same person can also be controlled through Redis. Key:uid+operation in Redis is restricted by increment (atomic manipulation).
Your requirements are concurrency security, that is, if you have multiple requests at the same time, each request involves querying, judging, updating such three steps, as multiple threads perform the first two operations at the same time, resulting in the judgment being bypassed.
Workaround:
1.redis Watch, will query to update the three steps to bind together, in fact, directly using REDIS transaction should be able to, without the use of watch, specifically, please test the actual
2. Using Redis to design a distributed lock, refer to the official scheme: Http://www.oschina.net/translate/redis-distlock
3. Use the queue to put the same user's request into the same queue, and then process