getCacheKey($key); $start = $this->time(); do { $lock = $this->redis()->set($lockName, $this->lockValue, ['nx', 'ex' => $lockTime]); if ($lock || $timeout === 0) { break; } // 默认 0.1 秒一次取锁 usleep(100000); } while ($this->time() < $start + $timeout); return $lock; } /** * 释放 Redis 锁 * * @param string $key * @return mixed */ public function delete(string $key) { $script = <<redis()->eval($script, [$this->getCacheKey($key), $this->lockValue], 1); } }