当前位置: 首页 » 产品 » 出口外贸 » 正文

PHP获取redis里不存在的6位随机数应用示例

放大字体  缩小字体 发布日期: 2024-10-26 12:21   来源:http://www.baidu.com/  作者:无忧资讯  浏览次数:29
核心提示:PHP获取6位数随机数PHP str_shuffle() 函数str_shuffle() 函数随机打乱字符串中的所有字符。参数描述 string必需。规定要打乱的

PHP获取6位数随机数

PHP str_shuffle() 函数

str_shuffle() 函数随机打乱字符串中的所有字符。

参数 描述
string   必需。规定要打乱的字符串。  

用php的str_shuffle函数:

<?php $randStr=str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'); $rand=substr($randStr,0,6); ?>

实例:获取redis里面不存在的6位随机数(设置24小时过时)

$port_number='1605D1BCC6C8027BA0223147652D67D6'; $send_number=$this->getSixRandNumber(); $rs=$this->redis->setKeyValue('ports:' . $send_number,$port_number); //以秒为最小单位 $this->redis->setTimeout('ports:' . $send_number,24*3600); protected function getSixRandNumber(){ $randStr=str_shuffle('1234567890'); $rand=substr($randStr,0,6); $port=$this->redis->getItemByKey('ports:' .$rand); //存在的重新取 if($port !=null){ return $this->getSixRandNumber(); } return $rand; }

 
 
[ 产品搜索 ]  [ 加入收藏 ]  [ 告诉好友 ]  [ 打印本文 ]  [ 违规举报 ]  [ 关闭窗口 ]

 

 
推荐图文
推荐产品
点击排行
    行业协会  备案信息  可信网站