34 lines
602 B
PHP
34 lines
602 B
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-12-1
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\api\models;
|
|
|
|
use app\models\Model;
|
|
|
|
class ApiModel extends Model
|
|
{
|
|
|
|
/**
|
|
* 重复提交锁
|
|
* @param $key
|
|
* @param $ttl
|
|
*/
|
|
public function lock($key, $ttl = 1)
|
|
{
|
|
$r = \Yii::$app->redis->incr($key);
|
|
\Yii::$app->redis->expire($key, $ttl); //设置生成时间为1秒
|
|
if ($r > 1) {
|
|
return $this->apiReturnError('请勿重复提交');
|
|
}
|
|
return true;
|
|
}
|
|
} |