1, 'max' => 100]; /** * 初始化 */ public function __construct() { Kiri::configure($this, config('redis', [])); } /** * @return void * @throws */ public function init(): void { } /** * @param $name * @param $arguments * @return mixed * @throws */ public function __call($name, $arguments): mixed { if (method_exists($this, $name)) { return $this->{$name}(...$arguments); } else { return $this->proxy($name, $arguments); } } /** * @param $key * @param int $timeout * @return bool * @throws */ public function waite($key, int $timeout = 5): bool { $time = time(); while (!$this->setNx($key, '1')) { if (time() - $time >= $timeout) { return FALSE; } usleep(1000); } $this->expire($key, $timeout); return TRUE; } /** * @param $key * @param int $timeout * @return bool|int * @throws */ public function lock($key, int $timeout = 5): bool|int { $script = <<