|  | 
| 13 | 13 | 
 | 
| 14 | 14 | use Hyperf\Config\Config; | 
| 15 | 15 | use Hyperf\Contract\ConfigInterface; | 
|  | 16 | +use Hyperf\Contract\StdoutLoggerInterface; | 
| 16 | 17 | use Hyperf\Di\Container; | 
|  | 18 | +use Hyperf\Engine\Channel as Chan; | 
| 17 | 19 | use Hyperf\Pool\Channel; | 
| 18 | 20 | use Hyperf\Pool\LowFrequencyInterface; | 
| 19 | 21 | use Hyperf\Pool\PoolOption; | 
| @@ -117,13 +119,48 @@ public function testRedisHScan() | 
| 117 | 119 |         $this->assertSame(0, $it); | 
| 118 | 120 |     } | 
| 119 | 121 | 
 | 
|  | 122 | +    public function testRedisPipeline() | 
|  | 123 | +    { | 
|  | 124 | +        $redis = $this->getRedis(); | 
|  | 125 | + | 
|  | 126 | +        $redis->rPush('pipeline:list', 'A'); | 
|  | 127 | +        $redis->rPush('pipeline:list', 'B'); | 
|  | 128 | +        $redis->rPush('pipeline:list', 'C'); | 
|  | 129 | +        $redis->rPush('pipeline:list', 'D'); | 
|  | 130 | +        $redis->rPush('pipeline:list', 'E'); | 
|  | 131 | + | 
|  | 132 | +        $chan = new Chan(1); | 
|  | 133 | +        $chan2 = new Chan(1); | 
|  | 134 | +        go(static function () use ($redis, $chan) { | 
|  | 135 | +            $redis->pipeline(); | 
|  | 136 | +            usleep(2000); | 
|  | 137 | +            $redis->lRange('pipeline:list', 0, 1); | 
|  | 138 | +            $redis->lTrim('pipeline:list', 2, -1); | 
|  | 139 | +            usleep(1000); | 
|  | 140 | +            $chan->push($redis->exec()); | 
|  | 141 | +        }); | 
|  | 142 | + | 
|  | 143 | +        go(static function () use ($redis, $chan2) { | 
|  | 144 | +            $redis->pipeline(); | 
|  | 145 | +            usleep(1000); | 
|  | 146 | +            $redis->lRange('pipeline:list', 0, 1); | 
|  | 147 | +            $redis->lTrim('pipeline:list', 2, -1); | 
|  | 148 | +            usleep(10000); | 
|  | 149 | +            $chan2->push($redis->exec()); | 
|  | 150 | +        }); | 
|  | 151 | + | 
|  | 152 | +        $this->assertSame([['A', 'B'], true], $chan->pop()); | 
|  | 153 | +        $this->assertSame([['C', 'D'], true], $chan2->pop()); | 
|  | 154 | +    } | 
|  | 155 | + | 
| 120 | 156 |     /** | 
| 121 | 157 |      * @param mixed $optinos | 
| 122 | 158 |      * @return \Redis | 
| 123 | 159 |      */ | 
| 124 | 160 |     private function getRedis($optinos = []) | 
| 125 | 161 |     { | 
| 126 | 162 |         $container = Mockery::mock(Container::class); | 
|  | 163 | +        $container->shouldReceive('has')->with(StdoutLoggerInterface::class)->andReturnFalse(); | 
| 127 | 164 |         $container->shouldReceive('get')->once()->with(ConfigInterface::class)->andReturn(new Config([ | 
| 128 | 165 |             'redis' => [ | 
| 129 | 166 |                 'default' => [ | 
|  | 
0 commit comments