|  | 
| 15 | 15 | use Hyperf\Contract\ConfigInterface; | 
| 16 | 16 | use Hyperf\Di\Container; | 
| 17 | 17 | use Hyperf\Pool\Channel; | 
|  | 18 | +use Hyperf\Pool\Exception\ConnectionException; | 
| 18 | 19 | use Hyperf\Pool\PoolOption; | 
| 19 | 20 | use Hyperf\Redis\Frequency; | 
| 20 | 21 | use Hyperf\Redis\Pool\PoolFactory; | 
| 21 | 22 | use Hyperf\Redis\Pool\RedisPool; | 
| 22 | 23 | use Hyperf\Redis\Redis; | 
|  | 24 | +use Hyperf\Redis\RedisProxy; | 
| 23 | 25 | use Hyperf\Utils\ApplicationContext; | 
| 24 | 26 | use Hyperf\Utils\Context; | 
| 25 | 27 | use Hyperf\Utils\Coroutine; | 
| @@ -137,6 +139,39 @@ public function testRedisReuseAfterThrowable() | 
| 137 | 139 |         $this->assertSame(1, $pool->getCurrentConnections()); | 
| 138 | 140 |     } | 
| 139 | 141 | 
 | 
|  | 142 | +    public function testRedisClusterConstructor() | 
|  | 143 | +    { | 
|  | 144 | +        $ref = new \ReflectionClass(\RedisCluster::class); | 
|  | 145 | +        $method = $ref->getMethod('__construct'); | 
|  | 146 | +        $names = [ | 
|  | 147 | +            'name', 'seeds', 'timeout', 'read_timeout', 'persistent', 'auth', | 
|  | 148 | +        ]; | 
|  | 149 | +        foreach ($method->getParameters() as $parameter) { | 
|  | 150 | +            $this->assertSame(array_shift($names), $parameter->getName()); | 
|  | 151 | +            if ($parameter->getName() === 'seeds') { | 
|  | 152 | +                $this->assertSame('array', $parameter->getType()->getName()); | 
|  | 153 | +            } else { | 
|  | 154 | +                $this->assertNull($parameter->getType()); | 
|  | 155 | +            } | 
|  | 156 | +        } | 
|  | 157 | +    } | 
|  | 158 | + | 
|  | 159 | +    public function testNewRedisCluster() | 
|  | 160 | +    { | 
|  | 161 | +        try { | 
|  | 162 | +            $container = $this->getContainer(); | 
|  | 163 | +            $pool = new RedisPoolStub($container, 'cluster1'); | 
|  | 164 | +            $container->shouldReceive('make')->once()->with(RedisPool::class, ['name' => 'cluster1'])->andReturn($pool); | 
|  | 165 | +            $factory = new PoolFactory($container); | 
|  | 166 | +            $redis = new RedisProxy($factory, 'cluster1'); | 
|  | 167 | +            $redis->get('test'); | 
|  | 168 | +            $this->assertTrue(false); | 
|  | 169 | +        } catch (\Throwable $exception) { | 
|  | 170 | +            $this->assertInstanceOf(ConnectionException::class, $exception); | 
|  | 171 | +            $this->assertStringNotContainsString('RedisCluster::__construct() expects parameter', $exception->getMessage()); | 
|  | 172 | +        } | 
|  | 173 | +    } | 
|  | 174 | + | 
| 140 | 175 |     private function getRedis() | 
| 141 | 176 |     { | 
| 142 | 177 |         $container = $this->getContainer(); | 
| @@ -168,6 +203,17 @@ private function getContainer() | 
| 168 | 203 |                         'max_idle_time' => 60, | 
| 169 | 204 |                     ], | 
| 170 | 205 |                 ], | 
|  | 206 | +                'cluster1' => [ | 
|  | 207 | +                    'timeout' => 1.0, | 
|  | 208 | +                    'auth' => null, | 
|  | 209 | +                    'cluster' => [ | 
|  | 210 | +                        'enable' => true, | 
|  | 211 | +                        'name' => 'mycluster', | 
|  | 212 | +                        'seeds' => [], | 
|  | 213 | +                        'read_timeout' => 1.0, | 
|  | 214 | +                        'persistent' => false, | 
|  | 215 | +                    ], | 
|  | 216 | +                ], | 
| 171 | 217 |             ], | 
| 172 | 218 |         ])); | 
| 173 | 219 |         $container->shouldReceive('make')->with(Frequency::class, Mockery::any())->andReturn(new Frequency()); | 
|  | 
0 commit comments