PHP Redis Hair Red Envelopes

Source: Internet
Author: User
Tags php redis
The requirement is this:

Now the company regularly send red envelopes, 1 times a week

Background Each period will be set
For example, 1 yuan of red Envelopes 10 2 yuan of 100 88 yuan of 10

There's a total number of red envelopes for each issue, like now I'm talking about the 3rd issue, the total number of red envelopes is 142.
Here is the settings for MySQL storage red envelopes

红包金额 数量   实际完成数量10        2         12         100       10088        10        320        30        22

The current process is this:
The user opens the page and starts to set the Memcache lock until the program finishes (unlocks). Because the red envelopes involved in making money, and combining
What time is that over there? The time is probably within 3s.
The logic inside the program is like this.
1: Determine if the user is eligible, such as the account is correct
2: Whether the user has robbed the red envelopes
3: Whether the number of red envelopes is reached
4: Randomly assign a red envelope (temporarily regardless of probability)
5: The red envelope that modifies the MySQL database the actual number of completed +1

In addition, I also think of using Redis's queue to use specific such:
1: Background to publish red envelopes when set a total
Set Red_money_count 142
When the user grabs the red envelope, put it in the queue and set it up with Rplush (principle is FIFO principle)
Then in the allocation of a red envelope, corresponding to the amount of the red envelope completed +1, but in this period is sure to and the exchange of money to make this time-consuming.
Now is the time-consuming problem to solve.

Note: At present, the use of memcache yoke implementation but also to queue users, must be 1 to finish the user experience is not good .....

Reply content:

The requirement is this:

Now the company regularly send red envelopes, 1 times a week

Background Each period will be set
For example, 1 yuan of red Envelopes 10 2 yuan of 100 88 yuan of 10

There's a total number of red envelopes for each issue, like now I'm talking about the 3rd issue, the total number of red envelopes is 142.
Here is the settings for MySQL storage red envelopes

红包金额 数量   实际完成数量10        2         12         100       10088        10        320        30        22

The current process is this:
The user opens the page and starts to set the Memcache lock until the program finishes (unlocks). Because the red envelopes involved in making money, and combining
What time is that over there? The time is probably within 3s.
The logic inside the program is like this.
1: Determine if the user is eligible, such as the account is correct
2: Whether the user has robbed the red envelopes
3: Whether the number of red envelopes is reached
4: Randomly assign a red envelope (temporarily regardless of probability)
5: The red envelope that modifies the MySQL database the actual number of completed +1

In addition, I also think of using Redis's queue to use specific such:
1: Background to publish red envelopes when set a total
Set Red_money_count 142
When the user grabs the red envelope, put it in the queue and set it up with Rplush (principle is FIFO principle)
Then in the allocation of a red envelope, corresponding to the amount of the red envelope completed +1, but in this period is sure to and the exchange of money to make this time-consuming.
Now is the time-consuming problem to solve.

Note: At present, the use of memcache yoke implementation but also to queue users, must be 1 to finish the user experience is not good .....

Direct use of MySQL to send red envelopes is not good, grab the red envelopes recorded in MySQL, and then according to the MySQL record to make money. MySQL inside the tag to grab the red envelopes, with the red envelopes and have been paid for it. Such a few red envelopes to what memcache,redis.

And the exchange of funds, return to the success of the data this time is about 3s.
This is not a time for you to write code to improve.

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