|
@@ -444,17 +444,18 @@ class Apic
|
|
|
if($redisconfig['redis_selectdb'] > 0){
|
|
|
$redis->select($redisconfig['redis_selectdb']);
|
|
|
}
|
|
|
- $check = $redis->exists($key);
|
|
|
- if ($check) {
|
|
|
- $redis->incr($key);
|
|
|
- $count = $redis->get($key);
|
|
|
- if ($count > $apiLimit) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- $redis->incr($key);
|
|
|
+ //
|
|
|
+ //指定键值新增+1 并获取
|
|
|
+ $count = $redis->incr($key);
|
|
|
+ if ($count > $apiLimit) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置过期时间
|
|
|
+ if ($count == 1) {
|
|
|
$redis->pExpire($key, $apiLimitTime);
|
|
|
}
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|