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!