How to process the app client at the code layer concurrent multiple requests concurrently with the individual?

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.