Skip to content

Commit 9e0de91

Browse files
authored
refactor(redis): 更新RedisCommand类的命名空间并移除已弃用的实现 (#851)
Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent 951593a commit 9e0de91

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/RedisCommand.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of friendsofhyperf/components.
6+
*
7+
* @link https://github.com/friendsofhyperf/components
8+
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
9+
* @contact huangdijia@gmail.com
10+
*/
11+
12+
namespace FriendsOfHyperf\Support;
13+
14+
use Stringable;
15+
16+
use function Hyperf\Collection\collect;
17+
18+
class RedisCommand implements Stringable
19+
{
20+
public function __construct(public string $command, public array $parameters = [])
21+
{
22+
}
23+
24+
public function __toString(): string
25+
{
26+
return $this->formatCommand($this->command, $this->parameters);
27+
}
28+
29+
protected function formatCommand(string $command, array $parameters): string
30+
{
31+
$parameters = collect($parameters)->map(function ($parameter) {
32+
if (is_array($parameter)) {
33+
return collect($parameter)->map(function ($value, $key) {
34+
if (is_array($value)) {
35+
return sprintf('%s %s', $key, json_encode($value));
36+
}
37+
38+
return is_int($key) ? $value : sprintf('%s %s', $key, $value);
39+
})->implode(' ');
40+
}
41+
42+
return $parameter;
43+
})->implode(' ');
44+
45+
return sprintf('%s %s', $command, $parameters);
46+
}
47+
}

0 commit comments

Comments
 (0)