get(PoolRedis::class); $config = $this->get_config(); $length = Config::get('cache.redis.pool.max', 10); $this->eventProvider->on(OnWorkerExit::class, [$this, 'destroy'], 0); $connections->initConnections('Redis:' . $config['host'], true, $length); } /** * @param $name * @param $arguments * @return mixed * @throws */ public function __call($name, $arguments): mixed { $time = microtime(true); if (method_exists($this, $name)) { $data = $this->{$name}(...$arguments); } else { $data = $this->proxy($name, $arguments); } if (microtime(true) - $time >= 0.02) { $this->warning('Redis:' . Json::encode([$name, $arguments]) . (microtime(true) - $time)); } return $data; } /** * @param $key * @param int $timeout * @return bool */ 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 Exception */ public function lock($key, int $timeout = 5): bool|int { $script = <<