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.
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