Example of using PHP to obtain a random number of six digits that does not exist in redis-php Tutorial

Source: Internet
Author: User
This article describes how to use PHP to obtain a random number of six digits that does not exist in redis. it can be set to a 24-hour out-of-date limit, involving php strings and database-related operation skills, for more information about how to use PHP to obtain a non-existent 6-digit random number in redis, you can set a 24-hour expiration time limit, involving php strings and database related operation skills, for more information, see

This example describes how to use PHP to obtain a random number of six digits that does not exist in redis. We will share this with you for your reference. The details are as follows:

PHP obtains a 6-digit random number.

PHPstr_shuffle()Function

The str_shuffle () function randomly disconnects all characters in the string.


Parameters Description
String Required. Specifies the string to be disrupted.

Use the str_shuffle function of php:

 

Instance: obtain the six-digit random number that does not exist in redis (set to 24 hours out of date)

$ Port_number = '1605d1bcc6c8027ba0223147652d67d6 '; $ send_number = $ this-> getSixRandNumber (); $ rs = $ this-> redis-> setKeyValue ('ports :'. $ send_number, $ port_number); // The smallest unit in seconds $ this-> redis-> setTimeout ('ports :'. $ send_number, 24*3600);/*** obtain a 6-digit random number */protected function getSixRandNumber () {$ randStr = str_shuffle ('123 '); $ rand = substr ($ randStr, 0, 6); $ port = $ this-> redis-> getItemByKey ('ports :'. $ rand );// If ($ port! = Null) {return $ this-> getSixRandNumber ();} return $ rand ;}

The above is the details of the example for PHP to obtain a non-existent 6-bit random number in redis. For more information, see other related articles in the first PHP community!

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.