Commit 2d408ccc authored by 734642908@qq.com's avatar 734642908@qq.com

测试自增id

parent e83d356e
...@@ -489,3 +489,8 @@ function curlPost($url,$data='',$is_ssl = false) { ...@@ -489,3 +489,8 @@ function curlPost($url,$data='',$is_ssl = false) {
curl_close($ch); curl_close($ch);
return $re; return $re;
} }
function getTime() {
list($microsecond , $time) = explode(' ', microtime()); //' '中间是一个空格
return (float)sprintf('%.0f',(floatval($microsecond)+floatval($time))*1000);
}
\ No newline at end of file
...@@ -69,6 +69,34 @@ class FlushController extends BaseController ...@@ -69,6 +69,34 @@ class FlushController extends BaseController
} }
public function testId() {
//连接本地的 Redis 服务
$redis = S(C('REDIS'));
while($redis->setnx('test_lock', getTime()+100)==0) {
if(getTime()>$redis->get('test_lock') && getTime()>$redis->getset('test_lock', getTime()+100)){
break;
}else{
usleep(100000);
}
}
$id = $redis->get('test_id');
if(empty($id)) {
$id = 100;
} else {
$id++;
}
$redis->set('test_id',$id);
echo $id;
$redis->del('test_lock');
}
} }
?> ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment