Skip to content

Commit e249ff2

Browse files
authored
Upgrade the minimum php version to 8.0 for load-balancer and redis. (#4359)
1 parent 691fb7e commit e249ff2

File tree

10 files changed

+26
-46
lines changed

10 files changed

+26
-46
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"source": "https://github.com/hyperf/hyperf"
1717
},
1818
"require": {
19-
"php": ">=7.2",
19+
"php": ">=8.0",
2020
"ext-redis": "*",
2121
"hyperf/contract": "~3.0.0",
2222
"hyperf/pool": "~3.0.0",

src/Lua/Hash/HIncrByFloatIfExists.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ public function getScript(): string
2727

2828
/**
2929
* @param null|float $data
30-
* @return null|float
3130
*/
32-
public function format($data)
31+
public function format($data): ?float
3332
{
3433
if (is_numeric($data)) {
35-
return $data;
34+
return (float) $data;
3635
}
3736
return null;
3837
}

src/Lua/Script.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,34 @@
1313

1414
use Hyperf\Contract\StdoutLoggerInterface;
1515
use Hyperf\Redis\Exception\RedisNotFoundException;
16+
use Hyperf\Redis\Redis;
1617
use Psr\Container\ContainerInterface;
18+
use Psr\Log\LoggerInterface;
1719

1820
abstract class Script implements ScriptInterface
1921
{
2022
/**
2123
* PHPRedis client or proxy client.
2224
* @var mixed|\Redis
2325
*/
24-
protected $redis;
26+
protected mixed $redis;
2527

26-
/**
27-
* @var null|string
28-
*/
29-
protected $sha;
28+
protected ?string $sha = null;
3029

31-
/**
32-
* @var StdoutLoggerInterface
33-
*/
34-
protected $logger;
30+
protected ?LoggerInterface $logger = null;
3531

3632
public function __construct(ContainerInterface $container)
3733
{
38-
if ($container->has(\Redis::class)) {
39-
$this->redis = $container->get(\Redis::class);
34+
if ($container->has(Redis::class)) {
35+
$this->redis = $container->get(Redis::class);
4036
}
4137

4238
if ($container->has(StdoutLoggerInterface::class)) {
4339
$this->logger = $container->get(StdoutLoggerInterface::class);
4440
}
4541
}
4642

47-
public function eval(array $arguments = [], $sha = true)
43+
public function eval(array $arguments = [], $sha = true): mixed
4844
{
4945
if ($this->redis === null) {
5046
throw new RedisNotFoundException('Redis client is not found.');

src/Lua/ScriptInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface ScriptInterface
1515
{
1616
public function getScript(): string;
1717

18-
public function format($data);
18+
public function format($data): mixed;
1919

20-
public function eval(array $arguments = [], $sha = true);
20+
public function eval(array $arguments = [], $sha = true): mixed;
2121
}

src/Pool/PoolFactory.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@
1616

1717
class PoolFactory
1818
{
19-
/**
20-
* @var ContainerInterface
21-
*/
22-
protected $container;
23-
2419
/**
2520
* @var RedisPool[]
2621
*/
27-
protected $pools = [];
22+
protected array $pools = [];
2823

29-
public function __construct(ContainerInterface $container)
24+
public function __construct(protected ContainerInterface $container)
3025
{
31-
$this->container = $container;
3226
}
3327

3428
public function getPool(string $name): RedisPool

src/Redis.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,10 @@ class Redis
2222
{
2323
use ScanCaller;
2424

25-
/**
26-
* @var PoolFactory
27-
*/
28-
protected $factory;
29-
30-
/**
31-
* @var string
32-
*/
33-
protected $poolName = 'default';
25+
protected string $poolName = 'default';
3426

35-
public function __construct(PoolFactory $factory)
27+
public function __construct(protected PoolFactory $factory)
3628
{
37-
$this->factory = $factory;
3829
}
3930

4031
public function __call($name, $arguments)
@@ -71,7 +62,7 @@ public function __call($name, $arguments)
7162
}
7263

7364
/**
74-
* Define the commands that needs same connection to execute.
65+
* Define the commands that need same connection to execute.
7566
* When these commands executed, the connection will storage to coroutine context.
7667
*/
7768
private function shouldUseSameConnection(string $methodName): bool

src/RedisFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RedisFactory
1919
/**
2020
* @var RedisProxy[]
2121
*/
22-
protected $proxies;
22+
protected array $proxies = [];
2323

2424
public function __construct(ConfigInterface $config)
2525
{
@@ -30,10 +30,7 @@ public function __construct(ConfigInterface $config)
3030
}
3131
}
3232

33-
/**
34-
* @return RedisProxy
35-
*/
36-
public function get(string $poolName)
33+
public function get(string $poolName): RedisProxy
3734
{
3835
$proxy = $this->proxies[$poolName] ?? null;
3936
if (! $proxy instanceof RedisProxy) {

src/RedisProxy.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
class RedisProxy extends Redis
2020
{
21-
protected $poolName;
22-
2321
public function __construct(PoolFactory $factory, string $pool)
2422
{
2523
parent::__construct($factory);

tests/Stub/ContainerStub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public static function mockContainer()
6363
$factory = new PoolFactory($container);
6464
return new Redis($factory);
6565
});
66+
$container->shouldReceive('has')->with(Redis::class)->andReturn(true);
67+
$container->shouldReceive('get')->with(Redis::class)->andReturnUsing(function () use ($container) {
68+
$factory = new PoolFactory($container);
69+
return new Redis($factory);
70+
});
6671
$container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturn(true);
6772
$container->shouldReceive('get')->with(StdoutLoggerInterface::class)->andReturn(value(function () {
6873
return Mockery::mock(StdoutLoggerInterface::class);

tests/Stub/HGetAllMultipleStub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515

1616
class HGetAllMultipleStub extends HGetAllMultiple
1717
{
18-
protected $sha = 'xxxx';
18+
protected ?string $sha = 'xxxx';
1919
}

0 commit comments

Comments
 (0)