Skip to content

Commit

Permalink
修复部分场景下出现的“Timeout of 3 seconds exceeded.”错误问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Jul 21, 2020
1 parent 1682be1 commit 07f2d18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/RateLimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function limitBlock($name, $capacity, $callback = null, $blockingT
{
$fill = $capacity;
}
$storage = new ImiRedisStorage($name, RedisManager::getInstance($poolName));
$storage = new ImiRedisStorage($name, RedisManager::getInstance($poolName), $blockingTimeout);
$rate = new Rate($fill, $unit);
$bucket = new TokenBucket($capacity, $rate, $storage);
$bucket->bootstrap($capacity);
Expand Down
5 changes: 3 additions & 2 deletions src/Storage/ImiRedisStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ final class ImiRedisStorage implements Storage, GlobalScope
*
* @param string $name The resource name.
* @param \Imi\Redis\RedisHandler $redis The Redis API.
* @param int $timeout
*/
public function __construct($name, \Imi\Redis\RedisHandler $redis)
public function __construct($name, \Imi\Redis\RedisHandler $redis, int $timeout = 3)
{
$this->key = $name;
$this->redis = $redis;
$this->mutex = new PHPRedisMutex([$redis], $name);
$this->mutex = new PHPRedisMutex([$redis], $name, $timeout);
}

public function bootstrap($microtime)
Expand Down

0 comments on commit 07f2d18

Please sign in to comment.