getCommand(); $command->setArguments($arguments); $this->assertSame($expected, $command->getArguments()); } /** * @group disconnected */ public function testFilterArgumentsNoCount(): void { $arguments = ['stream', '1-1', '0-1']; $expected = ['stream', '1-1', '0-1']; $command = $this->getCommand(); $command->setArguments($arguments); $this->assertSame($expected, $command->getArguments()); } /** * @group disconnected */ public function testParseResponse(): void { $raw = [['0-1', ['key', 'val']]]; $expected = ['0-1' => ['key' => 'val']]; $command = $this->getCommand(); $this->assertSame($expected, $command->parseResponse($raw)); } /** * @group disconnected */ public function testParseResponseMultipleKeys(): void { $raw = [['0-1', ['key1', 'val1', 'key2', 'val2']]]; $expected = ['0-1' => ['key1' => 'val1', 'key2' => 'val2']]; $command = $this->getCommand(); $this->assertSame($expected, $command->parseResponse($raw)); } /** * @group disconnected */ public function testPrefixKeys(): void { /** @var PrefixableCommand $command */ $command = $this->getCommand(); $actualArguments = ['arg1', 'arg2', 'arg3', 'arg4']; $prefix = 'prefix:'; $expectedArguments = ['prefix:arg1', 'arg2', 'arg3', 'COUNT', 'arg4']; $command->setArguments($actualArguments); $command->prefixKeys($prefix); $this->assertSame($expectedArguments, $command->getArguments()); } /** * @group connected * @requiresRedisVersion >= 5.0.0 */ public function testReturnsElementsInRange(): void { $redis = $this->getClient(); for ($i = 0; $i < 10; $i++) { $redis->xadd('stream', ['key' . $i => 'val' . $i], $i . '-1'); } $this->assertSame([], $redis->xrevrange('stream', '0-1', '1-1')); $this->assertSame( ['0-1' => ['key0' => 'val0']], $redis->xrevrange('stream', '0-1', '0-1') ); $this->assertSame( ['1-1' => ['key1' => 'val1'], '0-1' => ['key0' => 'val0']], $redis->xrevrange('stream', '1-1', '0-1') ); $this->assertSame( ['1-1' => ['key1' => 'val1'], '0-1' => ['key0' => 'val0']], $redis->xrevrange('stream', '1-1', '-') ); $this->assertSame( ['9-1' => ['key9' => 'val9'], '8-1' => ['key8' => 'val8']], $redis->xrevrange('stream', '+', '8-1') ); $this->assertSame( ['6-1' => ['key6' => 'val6'], '5-1' => ['key5' => 'val5']], $redis->xrevrange('stream', '6-1', '5-1') ); } /** * @group connected * @requiresRedisVersion >= 5.0.0 */ public function testMultipleKeys(): void { $redis = $this->getClient(); $redis->xadd('stream', ['key1' => 'val1', 'key2' => 'val2'], '0-1'); $redis->xadd('stream', ['key1' => 'val1', 'key2' => 'val2'], '1-1'); $this->assertSame( [ '1-1' => ['key1' => 'val1', 'key2' => 'val2'], '0-1' => ['key1' => 'val1', 'key2' => 'val2'], ], $redis->xrevrange('stream', '+', '-') ); } /** * @group connected * @requiresRedisVersion >= 6.0.0 */ public function testMultipleKeysResp3(): void { $redis = $this->getResp3Client(); $redis->xadd('stream', ['key1' => 'val1', 'key2' => 'val2'], '0-1'); $redis->xadd('stream', ['key1' => 'val1', 'key2' => 'val2'], '1-1'); $this->assertSame( [ '1-1' => ['key1' => 'val1', 'key2' => 'val2'], '0-1' => ['key1' => 'val1', 'key2' => 'val2'], ], $redis->xrevrange('stream', '+', '-') ); } /** * @group connected * @requiresRedisVersion >= 5.0.0 */ public function testThrowsExceptionOnWrongType(): void { $this->expectException('Predis\Response\ServerException'); $this->expectExceptionMessage('Operation against a key holding the wrong kind of value'); $redis = $this->getClient(); $redis->set('foo', 'bar'); $redis->xrevrange('foo', '1-1', '0-1'); } }