Using Redis in concurrent environments

Source: Internet
Author: User
  1. For a lottery, a user can only participate once by using the phone number as a check entry. The pre-entry number is "13311111111 0", the entrance first to determine the status of the user number is 0, for the first time to participate in the event, after the status update to 1. To avoid a number simultaneously clicking multiple times results in concurrent judgment errors of the entry. This uses Redis's "Setget 13311111111 1". The Setget command will feed back historical values. If 0 is returned, the user participates in the activity for the first time, and if feedback 1 the user is already active. The user has already participated in the activity as a reminder. Setget is an atomic operation in Redis and can be done as a function of the user's judgment and assignment. Avoid concurrency-caused judgment errors.

  2. The SETNX command is also an atomic operation if a key-value pair already exists that returns 0 if there is no return 1. Can be used to not pre-qualify the second kill or snapping scene. Achieve the atomicity of judgment and assignment operations.

Using Redis in concurrent environments

Related Article

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.