Skip to content

Commit

Permalink
Update: 修复代码分析与样式
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX committed Mar 29, 2024
1 parent ca3541f commit 786bf4d
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ public function bind(string $flag, int|string $clientId): void
*/
public function bindNx(string $flag, int|string $clientId): bool
{
$result = $this->useRedis(function (IRedisHandler $redis) use ($flag, $clientId) {
$result = $this->useRedis(fn (IRedisHandler $redis) =>
/** @var PhpRedisHandler|PredisHandler $redis */
return $redis->hSetNx($this->key . ':binder', $flag, $clientId);
});
$redis->hSetNx($this->key . ':binder', $flag, $clientId)
);
if ($result)
{
$this->lock((string) $clientId, function () use ($flag, $clientId): void {
Expand Down Expand Up @@ -243,21 +243,21 @@ public function unbind(string $flag, int|string $clientId, ?int $keepTime = null
*/
public function getClientIdByFlag(string $flag): array
{
return (array) $this->useRedis(function (IRedisHandler $redis) use ($flag) {
return (array) $this->useRedis(fn (IRedisHandler $redis) =>
/** @var PhpRedisHandler|PredisHandler $redis */
return $redis->hGet($this->key . ':binder', $flag) ?: null;
});
$redis->hGet($this->key . ':binder', $flag) ?: null
);
}

/**
* {@inheritDoc}
*/
public function getClientIdsByFlags(array $flags): array
{
$result = $this->useRedis(function (IRedisHandler $redis) use ($flags) {
$result = $this->useRedis(fn (IRedisHandler $redis) =>
/** @var PhpRedisHandler|PredisHandler $redis */
return $redis->hMget($this->key . ':binder', $flags);
});
$redis->hMget($this->key . ':binder', $flags)
);
foreach ($result as $k => $v)
{
$result[$k] = (array) $v;
Expand Down Expand Up @@ -293,14 +293,16 @@ public function getFlagsByClientIds(array $clientIds): array
*/
public function getOldClientIdByFlag(string $flag): ?int
{
return $this->useRedis(function (IRedisHandler $redis) use ($flag) {
return $this->useRedis(fn (IRedisHandler $redis) =>
/** @var PhpRedisHandler|PredisHandler $redis */
return $redis->get($this->key . ':binder:old:' . $flag) ?: null;
});
$redis->get($this->key . ':binder:old:' . $flag) ?: null
);
}

/**
* 使用redis.
*
* @param callable(PhpRedisHandler|PredisHandler): mixed $callback
*/
private function useRedis(callable $callback): mixed
{
Expand Down

0 comments on commit 786bf4d

Please sign in to comment.