Redis implements the sender, and redis implements the sender

Source: Internet
Author: User

Redis implements the sender, and redis implements the sender

The auto increment auto-increment id value of mysql may leak some sensitive data.

For example, if the user_id of the User table is auto-incrementing, the id value displayed in the url may expose the actual number of users on the website.

The following code uses php and redis's incrby to implement a simple Sender:

Function get_id ($ type, $ server_ip, $ server_port, $ key) {$ init_num = 0; $ redis = new Redis (); $ redis-> connect ($ server_ip, $ server_port); $ var = $ redis-> exists ($ key); if ($ var = 0) {$ redis-> set ($ key, $ init_num );} $ incr_num = rand (); // the incremental value is a random number $ var = $ redis-> incrby ($ key, $ incr_num); $ redis-> close (); return $ var ;}

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.