diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 44176155..785c7e53 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -79,8 +79,8 @@ use Predis\Response\Status; * @method int ttl(string $key) * @method mixed type(string $key) * @method int append(string $key, $value) - * @method int bfadd(string $key, $item) - * @method int bfexists(string $key, $item) + * @method mixed bfadd(string $key, $item) + * @method mixed bfexists(string $key, $item) * @method array bfinfo(string $key, string $modifier = '') * @method array bfinsert(string $key, int $capacity = -1, float $error = -1, int $expansion = -1, bool $noCreate = false, bool $nonScaling = false, string ...$item) * @method Status bfloadchunk(string $key, int $iterator, $data) @@ -96,11 +96,11 @@ use Predis\Response\Status; * @method array bzpopmax(array $keys, int $timeout) * @method array bzpopmin(array $keys, int $timeout) * @method array bzmpop(int $timeout, array $keys, string $modifier = 'min', int $count = 1) - * @method int cfadd(string $key, $item) - * @method int cfaddnx(string $key, $item) + * @method mixed cfadd(string $key, $item) + * @method mixed cfaddnx(string $key, $item) * @method int cfcount(string $key, $item) - * @method int cfdel(string $key, $item) - * @method int cfexists(string $key, $item) + * @method mixed cfdel(string $key, $item) + * @method mixed cfexists(string $key, $item) * @method Status cfloadchunk(string $key, int $iterator, $data) * @method int cfmexists(string $key, ...$item) * @method array cfinfo(string $key) @@ -185,8 +185,8 @@ use Predis\Response\Status; * @method array jsonarrtrim(string $key, string $path, int $start, int $stop) * @method int jsondel(string $key, string $path = '$') * @method int jsonforget(string $key, string $path = '$') - * @method string jsonget(string $key, string $indent = '', string $newline = '', string $space = '', string ...$paths) - * @method string jsonnumincrby(string $key, string $path, int $value) + * @method mixed jsonget(string $key, string $indent = '', string $newline = '', string $space = '', string ...$paths) + * @method mixed jsonnumincrby(string $key, string $path, int $value) * @method Status jsonmerge(string $key, string $path, string $value) * @method array jsonmget(array $keys, string $path) * @method Status jsonmset(string ...$keyPathValue) @@ -246,10 +246,10 @@ use Predis\Response\Status; * @method array tdigestcdf(string $key, int ...$value) * @method Status tdigestcreate(string $key, int $compression = 0) * @method array tdigestinfo(string $key) - * @method string tdigestmax(string $key) + * @method mixed tdigestmax(string $key) * @method Status tdigestmerge(string $destinationKey, array $sourceKeys, int $compression = 0, bool $override = false) * @method string[] tdigestquantile(string $key, float ...$quantile) - * @method string tdigestmin(string $key) + * @method mixed tdigestmin(string $key) * @method array tdigestrank(string $key, float ...$value) * @method Status tdigestreset(string $key) * @method array tdigestrevrank(string $key, float ...$value) diff --git a/src/Command/Redis/AbstractCommand/BZPOPBase.php b/src/Command/Redis/AbstractCommand/BZPOPBase.php index ed4a53b8..c2b4eae4 100644 --- a/src/Command/Redis/AbstractCommand/BZPOPBase.php +++ b/src/Command/Redis/AbstractCommand/BZPOPBase.php @@ -40,4 +40,13 @@ abstract class BZPOPBase extends RedisCommand return array_combine([$key], [[$data[0] => $data[1]]]); } + + /** + * @param $data + * @return array|false|mixed|null[]|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } } diff --git a/src/Command/Redis/CLIENT.php b/src/Command/Redis/CLIENT.php index 6c7bdc9c..2c779ef1 100644 --- a/src/Command/Redis/CLIENT.php +++ b/src/Command/Redis/CLIENT.php @@ -72,4 +72,13 @@ class CLIENT extends RedisCommand return $clients; } + + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } } diff --git a/src/Command/Redis/HSCAN.php b/src/Command/Redis/HSCAN.php index ca56b580..bc816738 100644 --- a/src/Command/Redis/HSCAN.php +++ b/src/Command/Redis/HSCAN.php @@ -84,6 +84,15 @@ class HSCAN extends RedisCommand return $data; } + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } + public function prefixKeys($prefix) { $this->applyPrefixForFirstArgument($prefix); diff --git a/src/Command/Redis/INFO.php b/src/Command/Redis/INFO.php index 26a62c2a..2fd11b6f 100644 --- a/src/Command/Redis/INFO.php +++ b/src/Command/Redis/INFO.php @@ -154,4 +154,13 @@ class INFO extends RedisCommand return $parsedData; } + + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } } diff --git a/src/Command/Redis/LMPOP.php b/src/Command/Redis/LMPOP.php index 12ef06bf..275a8b82 100644 --- a/src/Command/Redis/LMPOP.php +++ b/src/Command/Redis/LMPOP.php @@ -58,4 +58,9 @@ class LMPOP extends RedisCommand return [$data[0] => $data[1]]; } + + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } } diff --git a/src/Command/Redis/SLOWLOG.php b/src/Command/Redis/SLOWLOG.php index 41fbbcdc..ead2d9cd 100644 --- a/src/Command/Redis/SLOWLOG.php +++ b/src/Command/Redis/SLOWLOG.php @@ -49,4 +49,13 @@ class SLOWLOG extends RedisCommand return $data; } + + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } } diff --git a/src/Command/Redis/TopK/TOPKLIST.php b/src/Command/Redis/TopK/TOPKLIST.php index 11cbcfa5..19832974 100644 --- a/src/Command/Redis/TopK/TOPKLIST.php +++ b/src/Command/Redis/TopK/TOPKLIST.php @@ -53,6 +53,15 @@ class TOPKLIST extends RedisCommand return $data; } + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } + /** * Checks for the presence of the WITHCOUNT modifier. * diff --git a/src/Command/Redis/XRANGE.php b/src/Command/Redis/XRANGE.php index 46a2d488..6fda3bc6 100644 --- a/src/Command/Redis/XRANGE.php +++ b/src/Command/Redis/XRANGE.php @@ -60,6 +60,11 @@ class XRANGE extends RedisCommand return $result; } + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } + public function prefixKeys($prefix) { $this->applyPrefixForFirstArgument($prefix); diff --git a/src/Command/Redis/ZDIFF.php b/src/Command/Redis/ZDIFF.php index 573dcae6..50350927 100644 --- a/src/Command/Redis/ZDIFF.php +++ b/src/Command/Redis/ZDIFF.php @@ -45,4 +45,19 @@ class ZDIFF extends RedisCommand $this->setWithScore($arguments); } + + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + $parsedData = []; + + foreach ($data as $element) { + $parsedData[] = $this->parseResponse($element); + } + + return $parsedData; + } } diff --git a/src/Command/Redis/ZMPOP.php b/src/Command/Redis/ZMPOP.php index 4adc0cca..314907fa 100644 --- a/src/Command/Redis/ZMPOP.php +++ b/src/Command/Redis/ZMPOP.php @@ -76,4 +76,13 @@ class ZMPOP extends RedisCommand return array_combine([$key], [$parsedData]); } + + /** + * @param $data + * @return array|array[]|false|mixed|null[]|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } } diff --git a/src/Command/Redis/ZPOPMAX.php b/src/Command/Redis/ZPOPMAX.php index 1ebf45b0..5760f61e 100644 --- a/src/Command/Redis/ZPOPMAX.php +++ b/src/Command/Redis/ZPOPMAX.php @@ -44,4 +44,23 @@ class ZPOPMAX extends RedisCommand return $result; } + + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + $parsedData = []; + + foreach ($data as $element) { + if (is_array($element)) { + $parsedData[] = $this->parseResponse($element); + } else { + return $this->parseResponse($data); + } + } + + return $parsedData; + } } diff --git a/src/Command/Redis/ZPOPMIN.php b/src/Command/Redis/ZPOPMIN.php index 5f561c8e..7e326c3a 100644 --- a/src/Command/Redis/ZPOPMIN.php +++ b/src/Command/Redis/ZPOPMIN.php @@ -44,4 +44,23 @@ class ZPOPMIN extends RedisCommand return $result; } + + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + $parsedData = []; + + foreach ($data as $element) { + if (is_array($element)) { + $parsedData[] = $this->parseResponse($element); + } else { + return $this->parseResponse($data); + } + } + + return $parsedData; + } } diff --git a/src/Command/Redis/ZRANGE.php b/src/Command/Redis/ZRANGE.php index b2801c90..640028c4 100644 --- a/src/Command/Redis/ZRANGE.php +++ b/src/Command/Redis/ZRANGE.php @@ -107,6 +107,25 @@ class ZRANGE extends RedisCommand return $data; } + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + if (!is_array($data)) { + return $data; + } + + $parsedData = []; + + foreach ($data as $element) { + $parsedData[] = $this->parseResponse($element); + } + + return $parsedData; + } + public function prefixKeys($prefix) { $this->applyPrefixForFirstArgument($prefix); diff --git a/src/Command/Redis/ZSCAN.php b/src/Command/Redis/ZSCAN.php index 4b6a1c6e..130369f6 100644 --- a/src/Command/Redis/ZSCAN.php +++ b/src/Command/Redis/ZSCAN.php @@ -84,6 +84,15 @@ class ZSCAN extends RedisCommand return $data; } + /** + * @param $data + * @return array|mixed|string|null + */ + public function parseResp3Response($data) + { + return $this->parseResponse($data); + } + public function prefixKeys($prefix) { $this->applyPrefixForFirstArgument($prefix); diff --git a/src/Command/Traits/By/ByLexByScore.php b/src/Command/Traits/By/ByLexByScore.php index 66c53158..eb4a41b4 100644 --- a/src/Command/Traits/By/ByLexByScore.php +++ b/src/Command/Traits/By/ByLexByScore.php @@ -27,14 +27,14 @@ trait ByLexByScore public function setArguments(array $arguments) { - $argument = $arguments[static::$byLexByScoreArgumentPositionOffset]; - - if (false === $argument) { + if (count($arguments) <= static::$byLexByScoreArgumentPositionOffset || false === $arguments[static::$byLexByScoreArgumentPositionOffset]) { parent::setArguments($arguments); return; } + $argument = $arguments[static::$byLexByScoreArgumentPositionOffset]; + if (is_string($argument) && in_array(strtoupper($argument), self::$argumentsEnum)) { $argument = self::$argumentsEnum[$argument]; } else { diff --git a/src/Command/Traits/Rev.php b/src/Command/Traits/Rev.php index 20e7e686..f8ba8606 100644 --- a/src/Command/Traits/Rev.php +++ b/src/Command/Traits/Rev.php @@ -22,14 +22,14 @@ trait Rev { public function setArguments(array $arguments) { - $argument = $arguments[static::$revArgumentPositionOffset]; - - if (false === $argument) { + if (count($arguments) <= static::$revArgumentPositionOffset || false === $arguments[static::$revArgumentPositionOffset]) { parent::setArguments($arguments); return; } + $argument = $arguments[static::$revArgumentPositionOffset]; + if (true === $argument) { $argument = 'REV'; } else { diff --git a/src/Connection/StreamConnection.php b/src/Connection/StreamConnection.php index 2b546e3d..8fc60688 100644 --- a/src/Connection/StreamConnection.php +++ b/src/Connection/StreamConnection.php @@ -16,6 +16,8 @@ use InvalidArgumentException; use Predis\Command\CommandInterface; use Predis\Consumer\Push\PushNotificationException; use Predis\Consumer\Push\PushResponse; +use Predis\Protocol\Parser\Strategy\Resp2Strategy; +use Predis\Protocol\Parser\Strategy\Resp3Strategy; use Predis\Protocol\Parser\UnexpectedTypeException; use Predis\Response\Error; use Predis\Response\ErrorInterface as ErrorResponseInterface; @@ -305,7 +307,7 @@ class StreamConnection extends AbstractConnection } switch ($parsedData['type']) { - case 'push': + case Resp3Strategy::TYPE_PUSH: $data = []; for ($i = 0; $i < $parsedData['value']; ++$i) { @@ -313,7 +315,7 @@ class StreamConnection extends AbstractConnection } return new PushResponse($data); - case 'array': + case Resp2Strategy::TYPE_ARRAY: $data = []; for ($i = 0; $i < $parsedData['value']; ++$i) { @@ -322,18 +324,22 @@ class StreamConnection extends AbstractConnection return $data; - case 'bulkString': - case 'verbatimString': + case Resp2Strategy::TYPE_BULK_STRING: $bulkData = $this->readByChunks($socket, $parsedData['value']); return substr($bulkData, 0, -2); - case 'blobError': + case Resp3Strategy::TYPE_VERBATIM_STRING: + $bulkData = $this->readByChunks($socket, $parsedData['value']); + + return substr($bulkData, $parsedData['offset'], -2); + + case Resp3Strategy::TYPE_BLOB_ERROR: $errorMessage = $this->readByChunks($socket, $parsedData['value']); return new Error(substr($errorMessage, 0, -2)); - case 'map': + case Resp3Strategy::TYPE_MAP: $data = []; for ($i = 0; $i < $parsedData['value']; ++$i) { @@ -343,7 +349,7 @@ class StreamConnection extends AbstractConnection return $data; - case 'set': + case Resp3Strategy::TYPE_SET: $data = []; for ($i = 0; $i < $parsedData['value']; ++$i) { diff --git a/src/Protocol/Parser/Strategy/Resp2Strategy.php b/src/Protocol/Parser/Strategy/Resp2Strategy.php index 40e68fb0..b858640e 100644 --- a/src/Protocol/Parser/Strategy/Resp2Strategy.php +++ b/src/Protocol/Parser/Strategy/Resp2Strategy.php @@ -19,6 +19,9 @@ use Predis\Response\Status as StatusResponse; class Resp2Strategy implements ParserStrategyInterface { + public const TYPE_ARRAY = 'array'; + public const TYPE_BULK_STRING = 'bulkString'; + /** * Callbacks to process given RESP type. * @@ -113,7 +116,7 @@ class Resp2Strategy implements ParserStrategyInterface } return [ - 'type' => 'array', + 'type' => self::TYPE_ARRAY, 'value' => $count, ]; } @@ -133,7 +136,7 @@ class Resp2Strategy implements ParserStrategyInterface } return [ - 'type' => 'bulkString', + 'type' => self::TYPE_BULK_STRING, 'value' => $size, ]; } diff --git a/src/Protocol/Parser/Strategy/Resp3Strategy.php b/src/Protocol/Parser/Strategy/Resp3Strategy.php index 07f1d878..1ec85c74 100644 --- a/src/Protocol/Parser/Strategy/Resp3Strategy.php +++ b/src/Protocol/Parser/Strategy/Resp3Strategy.php @@ -14,6 +14,17 @@ namespace Predis\Protocol\Parser\Strategy; class Resp3Strategy extends Resp2Strategy { + public const TYPE_BLOB_ERROR = 'blobError'; + public const TYPE_VERBATIM_STRING = 'verbatimString'; + public const TYPE_MAP = 'map'; + public const TYPE_SET = 'set'; + public const TYPE_PUSH = 'push'; + + /** + * Verbatim string offset to skip file extension bytes. + */ + public const VERBATIM_STRING_EXTENSION_OFFSET = 4; + /** * @var string[] */ @@ -79,7 +90,7 @@ class Resp3Strategy extends Resp2Strategy protected function parseBlobError(string $string): array { return [ - 'type' => 'blobError', + 'type' => self::TYPE_BLOB_ERROR, 'value' => (int) $string, ]; } @@ -93,8 +104,9 @@ class Resp3Strategy extends Resp2Strategy protected function parseVerbatimString(string $string): array { return [ - 'type' => 'verbatimString', + 'type' => self::TYPE_VERBATIM_STRING, 'value' => (int) $string, + 'offset' => self::VERBATIM_STRING_EXTENSION_OFFSET, ]; } @@ -123,7 +135,7 @@ class Resp3Strategy extends Resp2Strategy protected function parseMap(string $string): array { return [ - 'type' => 'map', + 'type' => self::TYPE_MAP, 'value' => (int) $string, ]; } @@ -137,7 +149,7 @@ class Resp3Strategy extends Resp2Strategy protected function parseSet(string $string): array { return [ - 'type' => 'set', + 'type' => self::TYPE_SET, 'value' => (int) $string, ]; } @@ -151,7 +163,7 @@ class Resp3Strategy extends Resp2Strategy protected function parsePush(string $string): array { return [ - 'type' => 'push', + 'type' => self::TYPE_PUSH, 'value' => (int) $string, ]; } diff --git a/tests/PHPUnit/AssertSameWithPrecisionConstraint.php b/tests/PHPUnit/AssertSameWithPrecisionConstraint.php new file mode 100644 index 00000000..a96ea5c7 --- /dev/null +++ b/tests/PHPUnit/AssertSameWithPrecisionConstraint.php @@ -0,0 +1,81 @@ +expectedValue = $expectedValue; + $this->precision = $precision; + } + + /** + * {@inheritdoc} + */ + public function matches($other): bool + { + if (gettype($this->expectedValue) !== gettype($other)) { + return false; + } + + if (is_array($other)) { + $other = array_map([$this, 'roundToPrecision'], $other); + $this->expectedValue = array_map([$this, 'roundToPrecision'], $this->expectedValue); + + return !array_diff($this->expectedValue, $other); + } + + $other = $this->roundToPrecision($other); + $this->expectedValue = $this->roundToPrecision($this->expectedValue); + + return $other === $this->expectedValue; + } + + /** + * {@inheritDoc} + */ + public function toString(): string + { + return 'given value matches another value with given precision'; + } + + /** + * {@inheritdoc} + */ + protected function failureDescription($other): string + { + return $this->toString(); + } + + /** + * @param mixed $numeric + * @return float + */ + private function roundToPrecision($numeric): float + { + return round((float) $numeric, $this->precision); + } +} diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index d67829e8..1287a694 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -10,6 +10,7 @@ * file that was distributed with this source code. */ +use PHPUnit\AssertSameWithPrecisionConstraint; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\OneOfConstraint; use PHPUnit\Util\Test as TestUtil; @@ -131,6 +132,20 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase $this->assertThat($actual, new OneOfConstraint($expected), $message); } + /** + * Asserts that two values (of the same type) have the same values with given precision. + * + * @param mixed $expected Expected value + * @param mixed $actual Actual value + * @param int $precision Precision value should be round to + * @param string $message Optional assertion message + * @return void + */ + public function assertSameWithPrecision($expected, $actual, int $precision = 0, string $message = ''): void + { + $this->assertThat($actual, new AssertSameWithPrecisionConstraint($expected, $precision), $message); + } + /** * Asserts that a string matches a given regular expression. * diff --git a/tests/Predis/Command/Redis/APPEND_Test.php b/tests/Predis/Command/Redis/APPEND_Test.php index f0d7a721..bff09680 100644 --- a/tests/Predis/Command/Redis/APPEND_Test.php +++ b/tests/Predis/Command/Redis/APPEND_Test.php @@ -102,6 +102,18 @@ class APPEND_Test extends PredisCommandTestCase $this->assertSame('bar__bar', $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(3, $redis->append('foo', 'bar')); + $this->assertSame('bar', $redis->get('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/BITCOUNT_Test.php b/tests/Predis/Command/Redis/BITCOUNT_Test.php index 41a7e12b..162a8eeb 100644 --- a/tests/Predis/Command/Redis/BITCOUNT_Test.php +++ b/tests/Predis/Command/Redis/BITCOUNT_Test.php @@ -116,6 +116,24 @@ class BITCOUNT_Test extends PredisCommandTestCase $this->assertSame(1, $redis->bitcount('key', 0, 4, 'bit'), 'Count bits set (with range)'); } + /** + * @group connected + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsNumberOfBitsSetWithExplicitBitByteArgumentResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->setbit('key', 1, 1); + $redis->setbit('key', 10, 1); + $redis->setbit('key', 16, 1); + $redis->setbit('key', 22, 1); + $redis->setbit('key', 32, 1); + + $this->assertSame(2, $redis->bitcount('key', 0, 10, 'bit'), 'Count bits set (without range)'); + $this->assertSame(1, $redis->bitcount('key', 0, 4, 'bit'), 'Count bits set (with range)'); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/BITFIELD_Test.php b/tests/Predis/Command/Redis/BITFIELD_Test.php index 0099985b..ff45cbaf 100644 --- a/tests/Predis/Command/Redis/BITFIELD_Test.php +++ b/tests/Predis/Command/Redis/BITFIELD_Test.php @@ -122,6 +122,21 @@ class BITFIELD_Test extends PredisCommandTestCase $this->assertSame([128, 1, 128], $redis->bitfield('string', 'GET', 'u8', 0, 'GET', 'u8', 1, 'GET', 'u8', 8)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testBitfieldWithGetModifierResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->setbit('string', 0, 1); + $redis->setbit('string', 8, 1); + + $this->assertSame([128], $redis->bitfield('string', 'GET', 'u8', 0)); + $this->assertSame([128, 1, 128], $redis->bitfield('string', 'GET', 'u8', 0, 'GET', 'u8', 1, 'GET', 'u8', 8)); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/BITOP_Test.php b/tests/Predis/Command/Redis/BITOP_Test.php index fed9fe38..ded0d7e2 100644 --- a/tests/Predis/Command/Redis/BITOP_Test.php +++ b/tests/Predis/Command/Redis/BITOP_Test.php @@ -109,6 +109,21 @@ class BITOP_Test extends PredisCommandTestCase $this->assertSame("@\x00", $redis->get('key:dst')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCanPerformBitwiseANDResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('key:src:1', "h\x80"); + $redis->set('key:src:2', 'R'); + + $this->assertSame(2, $redis->bitop('AND', 'key:dst', 'key:src:1', 'key:src:2')); + $this->assertSame("@\x00", $redis->get('key:dst')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/BITPOS_Test.php b/tests/Predis/Command/Redis/BITPOS_Test.php index d0f9a107..401f1f61 100644 --- a/tests/Predis/Command/Redis/BITPOS_Test.php +++ b/tests/Predis/Command/Redis/BITPOS_Test.php @@ -98,6 +98,25 @@ class BITPOS_Test extends PredisCommandTestCase $this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range'); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsBitPositionResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->setbit('key', 10, 0); + $this->assertSame(0, $redis->bitpos('key', 0), 'Get position of first bit set to 0 - full range'); + $this->assertSame(-1, $redis->bitpos('key', 1), 'Get position of first bit set to 1 - full range'); + $this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range'); + + $redis->setbit('key', 5, 1); + $this->assertSame(0, $redis->bitpos('key', 0), 'Get position of first bit set to 0 - full range'); + $this->assertSame(5, $redis->bitpos('key', 1), 'Get position of first bit set to 1 - full range'); + $this->assertSame(-1, $redis->bitpos('key', 1, 5, 10), 'Get position of first bit set to 1 - specific range'); + } + /** * @group connected * @requiresRedisVersion >= 7.0.0 diff --git a/tests/Predis/Command/Redis/BLMOVE_Test.php b/tests/Predis/Command/Redis/BLMOVE_Test.php index 8e1c5b36..9da860dd 100644 --- a/tests/Predis/Command/Redis/BLMOVE_Test.php +++ b/tests/Predis/Command/Redis/BLMOVE_Test.php @@ -88,6 +88,31 @@ class BLMOVE_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedSecondList, $redis->lrange('test-blmove2', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsCorrectListElementResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('test-blmove1', ['element1', 'element2', 'element3']); + $redis->rpush('test-blmove2', ['element4', 'element5', 'element6']); + + $actualResponse = $redis->blmove( + 'test-blmove1', + 'test-blmove2', + 'LEFT', + 'LEFT', + 0 + ); + + $this->assertSame('element1', $actualResponse); + $this->assertSame(['element2', 'element3'], $redis->lrange('test-blmove1', 0, -1)); + $this->assertSame(['element1', 'element4', 'element5', 'element6'], $redis->lrange('test-blmove2', 0, -1)); + } + /** * @group connected * @dataProvider sameListProvider diff --git a/tests/Predis/Command/Redis/BLMPOP_Test.php b/tests/Predis/Command/Redis/BLMPOP_Test.php index a3b9c790..9f5fbae0 100644 --- a/tests/Predis/Command/Redis/BLMPOP_Test.php +++ b/tests/Predis/Command/Redis/BLMPOP_Test.php @@ -90,6 +90,22 @@ class BLMPOP_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedList, $redis->lrange($key, 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testPopElementsFromGivenListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->lpush('key', 'elem1', 'elem2', 'elem3'); + $actualResponse = $redis->blmpop(1, ['key1', 'key'], 'left', 1); + + $this->assertSame(['key' => ['elem3']], $actualResponse); + $this->assertSame(['elem2', 'elem1'], $redis->lrange('key', 0, -1)); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/BZMPOP_Test.php b/tests/Predis/Command/Redis/BZMPOP_Test.php index 27f11046..c751896a 100644 --- a/tests/Predis/Command/Redis/BZMPOP_Test.php +++ b/tests/Predis/Command/Redis/BZMPOP_Test.php @@ -65,7 +65,7 @@ class BZMPOP_Test extends PredisCommandTestCase * @param array $expectedResponse * @param array $expectedModifiedSortedSet * @return void - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 */ public function testReturnsPoppedElementsFromGivenSortedSet( int $timeout, @@ -85,6 +85,22 @@ class BZMPOP_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedSortedSet, $redis->zrange($key, 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsPoppedElementsFromGivenSortedSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-bzmpop', 1, 'member1', 2, 'member2', 3, 'member3'); + $actualResponse = $redis->bzmpop(1, ['test-bzmpop'], 'min', 1); + + $this->assertSame(['test-bzmpop' => ['member1' => 1.0]], $actualResponse); + $this->assertSame(['member2', 'member3'], $redis->zrange('test-bzmpop', 0, -1)); + } + /** * @group connected * @dataProvider unexpectedValuesProvider @@ -94,7 +110,7 @@ class BZMPOP_Test extends PredisCommandTestCase * @param int $count * @param string $expectedExceptionMessage * @return void - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 */ public function testThrowsExceptionOnUnexpectedValueGiven( int $timeout, @@ -113,7 +129,7 @@ class BZMPOP_Test extends PredisCommandTestCase /** * @group connected - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 */ public function testThrowsExceptionOnWrongType(): void { diff --git a/tests/Predis/Command/Redis/BZPOPMAX_Test.php b/tests/Predis/Command/Redis/BZPOPMAX_Test.php index d4d7b9aa..2145f672 100644 --- a/tests/Predis/Command/Redis/BZPOPMAX_Test.php +++ b/tests/Predis/Command/Redis/BZPOPMAX_Test.php @@ -51,6 +51,24 @@ class BZPOPMAX_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedSortedSet, $redis->zrange('test-bzpopmax', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsPoppedMaxElementFromGivenNonEmptySortedSetResp3(): void + { + $redis = $this->getResp3Client(); + $sortedSetDictionary = [1, 'member1', 2, 'member2', 3, 'member3']; + $expectedResponse = ['test-bzpopmax' => ['member3' => 3.0]]; + $expectedModifiedSortedSet = ['member1', 'member2']; + + $redis->zadd('test-bzpopmax', ...$sortedSetDictionary); + + $this->assertSame($expectedResponse, $redis->bzpopmax(['empty sorted set', 'test-bzpopmax'], 0)); + $this->assertSame($expectedModifiedSortedSet, $redis->zrange('test-bzpopmax', 0, -1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/BZPOPMIN_Test.php b/tests/Predis/Command/Redis/BZPOPMIN_Test.php index 115506c8..c5b0c04d 100644 --- a/tests/Predis/Command/Redis/BZPOPMIN_Test.php +++ b/tests/Predis/Command/Redis/BZPOPMIN_Test.php @@ -51,6 +51,24 @@ class BZPOPMIN_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedSortedSet, $redis->zrange('test-bzpopmin', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsPoppedMinElementFromGivenNonEmptySortedSetResp3(): void + { + $redis = $this->getResp3Client(); + $sortedSetDictionary = [1, 'member1', 2, 'member2', 3, 'member3']; + $expectedResponse = ['test-bzpopmin' => ['member1' => 1.0]]; + $expectedModifiedSortedSet = ['member2', 'member3']; + + $redis->zadd('test-bzpopmin', ...$sortedSetDictionary); + + $this->assertSame($expectedResponse, $redis->bzpopmin(['empty sorted set', 'test-bzpopmin'], 0)); + $this->assertSame($expectedModifiedSortedSet, $redis->zrange('test-bzpopmin', 0, -1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/BloomFilter/BFADD_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFADD_Test.php index 81bf9a90..a72293ba 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFADD_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFADD_Test.php @@ -62,7 +62,7 @@ class BFADD_Test extends PredisCommandTestCase /** * @group connected * @return void - * @requiresRedisBfVersion >= 1.0 + * @requiresRedisBfVersion >= 1.0.0 */ public function testAddGivenItemIntoBloomFilter(): void { @@ -75,7 +75,21 @@ class BFADD_Test extends PredisCommandTestCase /** * @group connected - * @requiresRedisBfVersion >= 1.0 + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testAddGivenItemIntoBloomFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->bfadd('key', 'item'); + $this->assertTrue($actualResponse); + $this->assertTrue($redis->bfexists('key', 'item')); + } + + /** + * @group connected + * @requiresRedisBfVersion >= 1.0.0 */ public function testThrowsExceptionOnWrongType(): void { diff --git a/tests/Predis/Command/Redis/BloomFilter/BFEXISTS_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFEXISTS_Test.php index 52845332..487f7122 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFEXISTS_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFEXISTS_Test.php @@ -61,7 +61,7 @@ class BFEXISTS_Test extends PredisCommandTestCase /** * @group connected * @return void - * @requiresRedisBfVersion >= 1.0 + * @requiresRedisBfVersion >= 1.0.0 */ public function testExistsReturnsExistingItemWithinBloomFilter(): void { @@ -72,4 +72,19 @@ class BFEXISTS_Test extends PredisCommandTestCase $this->assertSame(1, $redis->bfexists('key', 'item')); $this->assertSame(0, $redis->bfexists('key', 'non-existing')); } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testExistsReturnsExistingItemWithinBloomFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->bfadd('key', 'item'); + + $this->assertTrue($redis->bfexists('key', 'item')); + $this->assertFalse($redis->bfexists('key', 'non-existing')); + } } diff --git a/tests/Predis/Command/Redis/BloomFilter/BFINFO_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFINFO_Test.php index e83e17ce..7a2ad497 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFINFO_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFINFO_Test.php @@ -81,6 +81,24 @@ class BFINFO_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->bfinfo($key, $modifier)); } + /** + * @group connected + * @requiresRedisBfVersion 2.6.0 + */ + public function testInfoReturnsCorrectInformationAboutBloomFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->bfadd('key', 'item'); + $this->assertSame([ + 'Capacity' => 100, + 'Size' => 240, + 'Number of filters' => 1, + 'Number of items inserted' => 1, + 'Expansion rate' => 2, + ], $redis->bfinfo('key')); + } + /** * @group connected * @return void @@ -98,7 +116,7 @@ class BFINFO_Test extends PredisCommandTestCase /** * @group connected - * @requiresRedisBfVersion >= 1.0 + * @requiresRedisBfVersion >= 1.0.0 */ public function testThrowsExceptionOnWrongType(): void { diff --git a/tests/Predis/Command/Redis/BloomFilter/BFINSERT_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFINSERT_Test.php index a53bcc89..137ca9ff 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFINSERT_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFINSERT_Test.php @@ -84,6 +84,36 @@ class BFINSERT_Test extends PredisCommandTestCase $this->assertSame($expectedInfo, $redis->bfinfo($key, $modifier)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testInsertCreatesBloomFilterWithGivenItemsResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->bfinsert( + 'key', + -1, + -1, + -1, + false, + false, + 'item1', + 'item2' + ); + + $this->assertSame([true, true], $actualResponse); + $this->assertSame([ + 'Capacity' => 100, + 'Size' => 240, + 'Number of filters' => 1, + 'Number of items inserted' => 2, + 'Expansion rate' => 2, + ], $redis->bfinfo('key')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/BloomFilter/BFLOADCHUNK_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFLOADCHUNK_Test.php index 4e443aa1..850a9a27 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFLOADCHUNK_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFLOADCHUNK_Test.php @@ -95,6 +95,42 @@ class BFLOADCHUNK_Test extends PredisCommandTestCase $this->assertSame(1, $redis->bfexists('key', 'item1')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testLoadChunkSuccessfullyRestoresBloomFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->bfadd('key', 'item1'); + + $chunks = []; + $iter = 0; + + while (true) { + [$iter, $data] = $redis->bfscandump('key', $iter); + + if ($iter === 0) { + break; + } + + $chunks[] = [$iter, $data]; + } + + $redis->flushall(); + + foreach ($chunks as $chunk) { + [$iter, $data] = $chunk; + $actualResponse = $redis->bfloadchunk('key', $iter, $data); + + $this->assertEquals('OK', $actualResponse); + } + + $this->assertTrue($redis->bfexists('key', 'item1')); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/BloomFilter/BFMADD_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFMADD_Test.php index 5b0b4968..297c62e1 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFMADD_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFMADD_Test.php @@ -62,7 +62,7 @@ class BFMADD_Test extends PredisCommandTestCase /** * @group connected * @return void - * @requiresRedisBfVersion >= 1.0 + * @requiresRedisBfVersion >= 1.0.0 */ public function testAddGivenItemsIntoBloomFilter(): void { @@ -75,7 +75,21 @@ class BFMADD_Test extends PredisCommandTestCase /** * @group connected - * @requiresRedisBfVersion >= 1.0 + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testAddGivenItemsIntoBloomFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->bfmadd('key', 'item1', 'item2'); + $this->assertSame([true, true], $actualResponse); + $this->assertSame([true, true], $redis->bfmexists('key', 'item1', 'item2')); + } + + /** + * @group connected + * @requiresRedisBfVersion >= 1.0.0 */ public function testThrowsExceptionOnWrongType(): void { diff --git a/tests/Predis/Command/Redis/BloomFilter/BFMEXISTS_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFMEXISTS_Test.php index df151381..ee00371b 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFMEXISTS_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFMEXISTS_Test.php @@ -61,7 +61,7 @@ class BFMEXISTS_Test extends PredisCommandTestCase /** * @group connected * @return void - * @requiresRedisBfVersion >= 1.0 + * @requiresRedisBfVersion >= 1.0.0 */ public function testExistsReturnsExistingItemsWithinBloomFilter(): void { @@ -70,4 +70,17 @@ class BFMEXISTS_Test extends PredisCommandTestCase $redis->bfmadd('key', 'item1', 'item2'); $this->assertSame([1, 1], $redis->bfmexists('key', 'item1', 'item2')); } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testExistsReturnsExistingItemsWithinBloomFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->bfmadd('key', 'item1', 'item2'); + $this->assertSame([true, true], $redis->bfmexists('key', 'item1', 'item2')); + } } diff --git a/tests/Predis/Command/Redis/BloomFilter/BFRESERVE_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFRESERVE_Test.php index 1ac80529..74658e39 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFRESERVE_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFRESERVE_Test.php @@ -81,6 +81,20 @@ class BFRESERVE_Test extends PredisCommandTestCase $this->assertSame($expectedModification, $redis->bfinfo($key, $modifier)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReserveCreatesBloomFilterWithCorrectConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->bfreserve('key', 0.01, 100); + $this->assertEquals('OK', $actualResponse); + $this->assertSame(['Capacity' => 100], $redis->bfinfo('key', 'capacity')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/BloomFilter/BFSCANDUMP_Test.php b/tests/Predis/Command/Redis/BloomFilter/BFSCANDUMP_Test.php index 78f4a9ec..59523c6b 100644 --- a/tests/Predis/Command/Redis/BloomFilter/BFSCANDUMP_Test.php +++ b/tests/Predis/Command/Redis/BloomFilter/BFSCANDUMP_Test.php @@ -76,6 +76,23 @@ class BFSCANDUMP_Test extends PredisCommandTestCase $this->assertNotEmpty($dataChunk); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testScanDumpReturnsCorrectDataChunkResp3(): void + { + $expectedIterator = 1; + $redis = $this->getResp3Client(); + + $redis->bfadd('key', 'item1'); + [$iterator, $dataChunk] = $redis->bfscandump('key', 0); + + $this->assertSame($expectedIterator, $iterator); + $this->assertNotEmpty($dataChunk); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/CLIENT_Test.php b/tests/Predis/Command/Redis/CLIENT_Test.php index 41fe4176..0fc13d6a 100644 --- a/tests/Predis/Command/Redis/CLIENT_Test.php +++ b/tests/Predis/Command/Redis/CLIENT_Test.php @@ -143,6 +143,26 @@ BUFFER; $this->assertArrayHasKey('psub', $clients[0]); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsListOfConnectedClientsResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertIsArray($clients = $redis->client('LIST')); + $this->assertGreaterThanOrEqual(1, count($clients)); + $this->assertIsArray($clients[0]); + $this->assertArrayHasKey('addr', $clients[0]); + $this->assertArrayHasKey('fd', $clients[0]); + $this->assertArrayHasKey('idle', $clients[0]); + $this->assertArrayHasKey('flags', $clients[0]); + $this->assertArrayHasKey('db', $clients[0]); + $this->assertArrayHasKey('sub', $clients[0]); + $this->assertArrayHasKey('psub', $clients[0]); + } + /** * @group connected * @group relay-incompatible @@ -159,6 +179,21 @@ BUFFER; $this->assertEquals($expectedConnectionName, $redis->client('GETNAME')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testGetsNameOfConnectionResp3(): void + { + $redis = $this->getResp3Client(); + $clientName = $redis->client('GETNAME'); + $this->assertSame('predis', $clientName); + + $expectedConnectionName = 'foo-bar'; + $this->assertEquals('OK', $redis->client('SETNAME', $expectedConnectionName)); + $this->assertEquals($expectedConnectionName, $redis->client('GETNAME')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.9 diff --git a/tests/Predis/Command/Redis/COMMAND_Test.php b/tests/Predis/Command/Redis/COMMAND_Test.php index 47233988..27a326cd 100644 --- a/tests/Predis/Command/Redis/COMMAND_Test.php +++ b/tests/Predis/Command/Redis/COMMAND_Test.php @@ -95,6 +95,18 @@ class COMMAND_Test extends PredisCommandTestCase $this->assertSame([null], $response); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsEmptyCommandInfoOnNonExistingCommandResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertCount(1, $response = $redis->command('INFO', 'FOOBAR')); + $this->assertSame([null], $response); + } + /** * @group connected * @group relay-incompatible diff --git a/tests/Predis/Command/Redis/CONFIG_Test.php b/tests/Predis/Command/Redis/CONFIG_Test.php index cfb79196..ceada022 100644 --- a/tests/Predis/Command/Redis/CONFIG_Test.php +++ b/tests/Predis/Command/Redis/CONFIG_Test.php @@ -96,6 +96,21 @@ class CONFIG_Test extends PredisCommandTestCase $this->assertArrayHasKey('dbfilename', $configs); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsListOfConfigurationValuesResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertIsArray($configs = $redis->config('GET', '*')); + $this->assertGreaterThan(1, count($configs)); + $this->assertArrayHasKey('loglevel', $configs); + $this->assertArrayHasKey('appendonly', $configs); + $this->assertArrayHasKey('dbfilename', $configs); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 @@ -137,6 +152,23 @@ class CONFIG_Test extends PredisCommandTestCase $redis->config('SET', 'loglevel', $previous['loglevel']); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTrueOnSuccessfulConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $previous = $redis->config('GET', 'loglevel'); + + $this->assertEquals('OK', $redis->config('SET', 'loglevel', 'notice')); + $this->assertSame(['loglevel' => 'notice'], $redis->config('GET', 'loglevel')); + + // We set the loglevel configuration to the previous value. + $redis->config('SET', 'loglevel', $previous['loglevel']); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 @@ -168,6 +200,17 @@ class CONFIG_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->config('RESETSTAT')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTrueOnResetstatResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->config('RESETSTAT')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/COPY_Test.php b/tests/Predis/Command/Redis/COPY_Test.php index 241a1521..eec9e3e2 100644 --- a/tests/Predis/Command/Redis/COPY_Test.php +++ b/tests/Predis/Command/Redis/COPY_Test.php @@ -66,6 +66,22 @@ class COPY_Test extends PredisCommandTestCase $this->assertSame($redis->get('key'), $redis->get('destination')); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testSuccessfullyCopyValueOnNonExistingDestinationKeyResp3(): void + { + $redis = $this->getResp3Client(); + $redis->set('key', 'value'); + + $actualResponse = $redis->copy('key', 'destination'); + + $this->assertSame(1, $actualResponse); + $this->assertSame($redis->get('key'), $redis->get('destination')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/CountMinSketch/CMSINCRBY_Test.php b/tests/Predis/Command/Redis/CountMinSketch/CMSINCRBY_Test.php index d58779f1..2f72fbba 100644 --- a/tests/Predis/Command/Redis/CountMinSketch/CMSINCRBY_Test.php +++ b/tests/Predis/Command/Redis/CountMinSketch/CMSINCRBY_Test.php @@ -84,6 +84,24 @@ class CMSINCRBY_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $queryResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testIncrementGivenItemsWithinCountMinSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cmsinitbydim('key', 2000, 7); + + $actualResponse = $redis->cmsincrby('key', 'item1', 1); + $queryResponse = $redis->cmsquery('key', 'item1'); + + $this->assertSame([1], $actualResponse); + $this->assertSame([1], $queryResponse); + } + /** * @group connected * @requiresRedisBfVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/CountMinSketch/CMSINFO_Test.php b/tests/Predis/Command/Redis/CountMinSketch/CMSINFO_Test.php index 3f44471f..020b4c94 100644 --- a/tests/Predis/Command/Redis/CountMinSketch/CMSINFO_Test.php +++ b/tests/Predis/Command/Redis/CountMinSketch/CMSINFO_Test.php @@ -79,6 +79,23 @@ class CMSINFO_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsInfoAboutGivenCountMinSketchResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = ['width' => 2000, 'depth' => 10, 'count' => 0]; + + $redis->cmsinitbydim('key', 2000, 10); + + $actualResponse = $redis->cmsinfo('key'); + + $this->assertSame($expectedResponse, $actualResponse); + } + /** * @group connected * @requiresRedisBfVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYDIM_Test.php b/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYDIM_Test.php index 4449ba62..a61fd982 100644 --- a/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYDIM_Test.php +++ b/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYDIM_Test.php @@ -76,6 +76,23 @@ class CMSINITBYDIM_Test extends PredisCommandTestCase $this->assertSame(10, $info['depth']); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testInitializeCountMinSketchWithGivenConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->cmsinitbydim('key', 2000, 10); + $info = $redis->cmsinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(2000, $info['width']); + $this->assertSame(10, $info['depth']); + } + /** * @group connected * @requiresRedisBfVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYPROB_Test.php b/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYPROB_Test.php index f280456f..b29ee416 100644 --- a/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYPROB_Test.php +++ b/tests/Predis/Command/Redis/CountMinSketch/CMSINITBYPROB_Test.php @@ -76,6 +76,23 @@ class CMSINITBYPROB_Test extends PredisCommandTestCase $this->assertSame(7, $info['depth']); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testInitializeCountMinSketchWithDesiredErrorRateAndProbabilityResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->cmsinitbyprob('key', 0.001, 0.01); + $info = $redis->cmsinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(2000, $info['width']); + $this->assertSame(7, $info['depth']); + } + /** * @group connected * @requiresRedisBfVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/CountMinSketch/CMSMERGE_Test.php b/tests/Predis/Command/Redis/CountMinSketch/CMSMERGE_Test.php index 42eb687c..8bce102f 100644 --- a/tests/Predis/Command/Redis/CountMinSketch/CMSMERGE_Test.php +++ b/tests/Predis/Command/Redis/CountMinSketch/CMSMERGE_Test.php @@ -87,6 +87,27 @@ class CMSMERGE_Test extends PredisCommandTestCase $this->assertSame($expectedCounts, $redis->cmsquery('destination', ...$items)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testMergeSketchesAndSaveWithinDestinationCountMinSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cmsinitbyprob('source1', 0.001, 0.01); + $redis->cmsinitbyprob('source2', 0.001, 0.01); + $redis->cmsinitbyprob('destination', 0.001, 0.01); + $redis->cmsincrby('source1', 'item1', 1, 'item2', 1); + $redis->cmsincrby('source2', 'item1', 1, 'item2', 1); + + $actualResponse = $redis->cmsmerge('destination', ['source1', 'source2']); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame([2, 2], $redis->cmsquery('destination', 'item1', 'item2')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/CountMinSketch/CMSQUERY_Test.php b/tests/Predis/Command/Redis/CountMinSketch/CMSQUERY_Test.php index f3335a61..2f40d4b3 100644 --- a/tests/Predis/Command/Redis/CountMinSketch/CMSQUERY_Test.php +++ b/tests/Predis/Command/Redis/CountMinSketch/CMSQUERY_Test.php @@ -79,6 +79,21 @@ class CMSQUERY_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnCountValuesForGivenItemsWithinCountMinSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cmsinitbydim('key', 2000, 7); + + $actualResponse = $redis->cmsquery('key', 'item1'); + $this->assertSame([0], $actualResponse); + } + /** * @group connected * @requiresRedisBfVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFADDNX_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFADDNX_Test.php index 94a6960b..f92a1809 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFADDNX_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFADDNX_Test.php @@ -77,6 +77,24 @@ class CFADDNX_Test extends PredisCommandTestCase $this->assertSame(1, $redis->cfexists('key', 'item')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testAddItemToCuckooFilterWhenExistsResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->cfaddnx('key', 'item'); + $this->assertTrue($actualResponse); + $this->assertTrue($redis->cfexists('key', 'item')); + + $actualResponse = $redis->cfaddnx('key', 'item'); + $this->assertFalse($actualResponse); + $this->assertTrue($redis->cfexists('key', 'item')); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFADD_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFADD_Test.php index 95f72990..b482ca69 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFADD_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFADD_Test.php @@ -73,6 +73,20 @@ class CFADD_Test extends PredisCommandTestCase $this->assertSame(1, $redis->cfexists('key', 'item')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testAddItemToCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->cfadd('key', 'item'); + $this->assertTrue($actualResponse); + $this->assertTrue($redis->cfexists('key', 'item')); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFCOUNT_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFCOUNT_Test.php index 76306df7..0d6746f9 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFCOUNT_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFCOUNT_Test.php @@ -81,4 +81,28 @@ class CFCOUNT_Test extends PredisCommandTestCase $nonExistingItemResponse = $redis->cfcount('non_existing_key', 'item'); $this->assertSame(0, $nonExistingItemResponse); } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsCountOfItemsWithinCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cfadd('key', 'item'); + + $singleItemResponse = $redis->cfcount('key', 'item'); + $this->assertSame(1, $singleItemResponse); + + $redis->cfadd('key', 'item'); + $redis->cfadd('key', 'item'); + + $multipleItemsResponse = $redis->cfcount('key', 'item'); + $this->assertSame(3, $multipleItemsResponse); + + $nonExistingItemResponse = $redis->cfcount('non_existing_key', 'item'); + $this->assertSame(0, $nonExistingItemResponse); + } } diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFDEL_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFDEL_Test.php index 70f2c098..baf645cd 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFDEL_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFDEL_Test.php @@ -85,6 +85,32 @@ class CFDEL_Test extends PredisCommandTestCase $this->assertSame(0, $nonExistingItemResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testDeletesItemFromGivenCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cfadd('key', 'item'); + $singleItemResponse = $redis->cfdel('key', 'item'); + + $this->assertTrue($singleItemResponse); + $this->assertFalse($redis->cfexists('key', 'item')); + + $redis->cfadd('key', 'item'); + $redis->cfadd('key', 'item'); + + $multipleItemsResponse = $redis->cfdel('key', 'item'); + $this->assertTrue($multipleItemsResponse); + $this->assertTrue($redis->cfexists('key', 'item')); + + $nonExistingItemResponse = $redis->cfdel('key', 'non_existing_item'); + $this->assertFalse($nonExistingItemResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php index 78f6d021..851b3065 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFEXISTS_Test.php @@ -72,4 +72,19 @@ class CFEXISTS_Test extends PredisCommandTestCase $this->assertSame(1, $redis->cfexists('key', 'item')); $this->assertSame(0, $redis->cfexists('non-existing key', 'item')); } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testExistsReturnsExistingItemWithinCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cfadd('key', 'item'); + + $this->assertTrue($redis->cfexists('key', 'item')); + $this->assertFalse($redis->cfexists('non-existing key', 'item')); + } } diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFINFO_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFINFO_Test.php index 72ab27f2..ed6bb914 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFINFO_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFINFO_Test.php @@ -84,6 +84,30 @@ class CFINFO_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->cfinfo('key')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testInfoReturnsInformationAboutGivenCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [ + 'Size' => 1080, + 'Number of buckets' => 512, + 'Number of filters' => 1, + 'Number of items inserted' => 1, + 'Number of items deleted' => 0, + 'Bucket size' => 2, + 'Expansion rate' => 1, + 'Max iterations' => 20, + ]; + + $redis->cfadd('key', 'item'); + + $this->assertSame($expectedResponse, $redis->cfinfo('key')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFINSERTNX_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFINSERTNX_Test.php index 1f8a1da4..f75a5c2b 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFINSERTNX_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFINSERTNX_Test.php @@ -90,6 +90,22 @@ class CFINSERTNX_Test extends PredisCommandTestCase $this->assertSame([0, 0], $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testDoNotInsertAlreadyExistingItemsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cfadd('filter', 'item1'); + $redis->cfadd('filter', 'item2'); + + $actualResponse = $redis->cfinsertnx('filter', -1, false, 'item1', 'item2'); + $this->assertSame([0, 0], $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFINSERT_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFINSERT_Test.php index 90104060..c46aa7fd 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFINSERT_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFINSERT_Test.php @@ -93,6 +93,24 @@ class CFINSERT_Test extends PredisCommandTestCase $this->assertSame(1080, $info['Size']); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testInsertIgnoresCapacityModifierOnAlreadyExistingFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cfadd('filter', 'item'); + + $actualResponse = $redis->cfinsert('filter', 500, false, 'item1'); + $info = $redis->cfinfo('filter'); + + $this->assertSame([true], $actualResponse); + $this->assertSame(1080, $info['Size']); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFLOADCHUNK_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFLOADCHUNK_Test.php index aaa738f9..82a0326f 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFLOADCHUNK_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFLOADCHUNK_Test.php @@ -95,6 +95,42 @@ class CFLOADCHUNK_Test extends PredisCommandTestCase $this->assertSame(1, $redis->cfexists('key', 'item1')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testLoadChunkSuccessfullyRestoresCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->cfadd('key', 'item1'); + + $chunks = []; + $iter = 0; + + while (true) { + [$iter, $data] = $redis->cfscandump('key', $iter); + + if ($iter === 0) { + break; + } + + $chunks[] = [$iter, $data]; + } + + $redis->flushall(); + + foreach ($chunks as $chunk) { + [$iter, $data] = $chunk; + $actualResponse = $redis->cfloadchunk('key', $iter, $data); + + $this->assertEquals('OK', $actualResponse); + } + + $this->assertTrue($redis->cfexists('key', 'item1')); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFMEXISTS_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFMEXISTS_Test.php index a1b91ca0..1fd3729b 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFMEXISTS_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFMEXISTS_Test.php @@ -61,7 +61,7 @@ class CFMEXISTS_Test extends PredisCommandTestCase /** * @group connected * @return void - * @requiresRedisBfVersion >= 1.0 + * @requiresRedisBfVersion >= 1.0.0 */ public function testExistsReturnsExistingItemsWithinCuckooFilter(): void { @@ -74,4 +74,21 @@ class CFMEXISTS_Test extends PredisCommandTestCase $redis->cfadd('key', 'item3'); $this->assertSame([1, 1, 1], $redis->cfmexists('key', 'item1', 'item2', 'item3')); } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testExistsReturnsExistingItemsWithinCuckooFilterResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame([false, false, false], $redis->cfmexists('key', 'item1', 'item2', 'item3')); + $redis->cfadd('key', 'item1'); + $this->assertSame([true, false, false], $redis->cfmexists('key', 'item1', 'item2', 'item3')); + $redis->cfadd('key', 'item2'); + $redis->cfadd('key', 'item3'); + $this->assertSame([true, true, true], $redis->cfmexists('key', 'item1', 'item2', 'item3')); + } } diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFRESERVE_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFRESERVE_Test.php index eef7b021..70d4011f 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFRESERVE_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFRESERVE_Test.php @@ -80,6 +80,26 @@ class CFRESERVE_Test extends PredisCommandTestCase $this->assertSame($expectedExpansion, $info['Expansion rate']); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReserveCreatesCuckooFilterWithCorrectConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->cfreserve('key', 500); + $this->assertEquals('OK', $actualResponse); + + $info = $redis->cfinfo('key'); + + $this->assertSame(568, $info['Size']); + $this->assertSame(2, $info['Bucket size']); + $this->assertSame(20, $info['Max iterations']); + $this->assertSame(1, $info['Expansion rate']); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/CuckooFilter/CFSCANDUMP_Test.php b/tests/Predis/Command/Redis/CuckooFilter/CFSCANDUMP_Test.php index 1e6b5983..1db8183b 100644 --- a/tests/Predis/Command/Redis/CuckooFilter/CFSCANDUMP_Test.php +++ b/tests/Predis/Command/Redis/CuckooFilter/CFSCANDUMP_Test.php @@ -76,6 +76,23 @@ class CFSCANDUMP_Test extends PredisCommandTestCase $this->assertNotEmpty($dataChunk); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testScanDumpReturnsNotEmptyDataChunkResp3(): void + { + $expectedIterator = 1; + $redis = $this->getResp3Client(); + + $redis->cfadd('key', 'item1'); + [$iterator, $dataChunk] = $redis->cfscandump('key', 0); + + $this->assertSame($expectedIterator, $iterator); + $this->assertNotEmpty($dataChunk); + } + /** * @group connected * @requiresRedisBfVersion >= 1.0.0 diff --git a/tests/Predis/Command/Redis/DBSIZE_Test.php b/tests/Predis/Command/Redis/DBSIZE_Test.php index cc946cae..7904de70 100644 --- a/tests/Predis/Command/Redis/DBSIZE_Test.php +++ b/tests/Predis/Command/Redis/DBSIZE_Test.php @@ -63,4 +63,16 @@ class DBSIZE_Test extends PredisCommandTestCase $redis->set('foo', 'bar'); $this->assertGreaterThan(0, $redis->dbsize()); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsCurrentSizeOfDatabaseResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $this->assertGreaterThan(0, $redis->dbsize()); + } } diff --git a/tests/Predis/Command/Redis/DECRBY_Test.php b/tests/Predis/Command/Redis/DECRBY_Test.php index 2288dda1..ea3cf0d6 100644 --- a/tests/Predis/Command/Redis/DECRBY_Test.php +++ b/tests/Predis/Command/Redis/DECRBY_Test.php @@ -86,6 +86,18 @@ class DECRBY_Test extends PredisCommandTestCase $this->assertEquals(-10, $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(-10, $redis->decrby('foo', 10)); + $this->assertEquals(-10, $redis->get('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/DECR_Test.php b/tests/Predis/Command/Redis/DECR_Test.php index 9e16e7ec..e05805d6 100644 --- a/tests/Predis/Command/Redis/DECR_Test.php +++ b/tests/Predis/Command/Redis/DECR_Test.php @@ -86,6 +86,18 @@ class DECR_Test extends PredisCommandTestCase $this->assertEquals(-1, $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(-1, $redis->decr('foo')); + $this->assertEquals(-1, $redis->get('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/DEL_Test.php b/tests/Predis/Command/Redis/DEL_Test.php index 241e493b..2e877e0c 100644 --- a/tests/Predis/Command/Redis/DEL_Test.php +++ b/tests/Predis/Command/Redis/DEL_Test.php @@ -109,4 +109,25 @@ class DEL_Test extends PredisCommandTestCase $redis->set('hoge', 'piyo'); $this->assertSame(2, $redis->del('foo', 'hoge')); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsNumberOfDeletedKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(0, $redis->del('foo')); + + $redis->set('foo', 'bar'); + $this->assertSame(1, $redis->del('foo')); + + $redis->set('foo', 'bar'); + $this->assertSame(1, $redis->del('foo', 'hoge')); + + $redis->set('foo', 'bar'); + $redis->set('hoge', 'piyo'); + $this->assertSame(2, $redis->del('foo', 'hoge')); + } } diff --git a/tests/Predis/Command/Redis/DISCARD_Test.php b/tests/Predis/Command/Redis/DISCARD_Test.php index b54c92c3..94105674 100644 --- a/tests/Predis/Command/Redis/DISCARD_Test.php +++ b/tests/Predis/Command/Redis/DISCARD_Test.php @@ -85,6 +85,22 @@ class DISCARD_Test extends PredisCommandTestCase $this->assertSame(0, $redis->exists('foo')); } + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testAbortsTransactionAndRestoresNormalFlowResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->multi(); + + $this->assertEquals('QUEUED', $redis->set('foo', 'bar')); + $this->assertEquals('OK', $redis->discard()); + $this->assertSame(0, $redis->exists('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ECHO_Test.php b/tests/Predis/Command/Redis/ECHO_Test.php index 26af4807..b70d4c1c 100644 --- a/tests/Predis/Command/Redis/ECHO_Test.php +++ b/tests/Predis/Command/Redis/ECHO_Test.php @@ -72,4 +72,17 @@ class ECHO_Test extends PredisCommandTestCase $this->assertSame($message, $redis->echo($message)); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testAlwaysReturnsThePassedMessageResp3(): void + { + $redis = $this->getResp3Client(); + + $message = 'Can you hear me?'; + + $this->assertSame($message, $redis->echo($message)); + } } diff --git a/tests/Predis/Command/Redis/EVALSHA_RO_Test.php b/tests/Predis/Command/Redis/EVALSHA_RO_Test.php index 74ad40ce..74a577a8 100644 --- a/tests/Predis/Command/Redis/EVALSHA_RO_Test.php +++ b/tests/Predis/Command/Redis/EVALSHA_RO_Test.php @@ -81,6 +81,20 @@ class EVALSHA_RO_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->evalsha_ro($sha1, $keys, ...$arguments)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testExecutesReadOnlyCachedScriptsResp3(): void + { + $redis = $this->getClient(); + + $sha1 = $redis->script('LOAD', "return 'test'"); + + $this->assertSame('test', $redis->evalsha_ro($sha1, [])); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/EVALSHA_Test.php b/tests/Predis/Command/Redis/EVALSHA_Test.php index 81b67715..b3cba8f4 100644 --- a/tests/Predis/Command/Redis/EVALSHA_Test.php +++ b/tests/Predis/Command/Redis/EVALSHA_Test.php @@ -100,6 +100,22 @@ class EVALSHA_Test extends PredisCommandTestCase $this->assertSame($result, $redis->evalsha($sha1, 2, 'foo', 'hoge', 'bar', 'piyo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testExecutesSpecifiedLuaScriptResp3(): void + { + $redis = $this->getResp3Client(); + + $lua = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'; + $sha1 = sha1($lua); + $result = ['foo', 'hoge', 'bar', 'piyo']; + + $this->assertSame($result, $redis->eval($lua, 2, 'foo', 'hoge', 'bar', 'piyo')); + $this->assertSame($result, $redis->evalsha($sha1, 2, 'foo', 'hoge', 'bar', 'piyo')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/EVAL_RO_Test.php b/tests/Predis/Command/Redis/EVAL_RO_Test.php index cdeb5b70..a714035a 100644 --- a/tests/Predis/Command/Redis/EVAL_RO_Test.php +++ b/tests/Predis/Command/Redis/EVAL_RO_Test.php @@ -83,6 +83,20 @@ class EVAL_RO_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->eval_ro($script, $keys, ...$arguments)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testExecutesReadOnlyCommandsFromGivenLuaScriptResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->mset('key', 'value'); + + $this->assertSame('value', $redis->eval_ro("return redis.call('GET', KEYS[1])", ['key'])); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/EVAL_Test.php b/tests/Predis/Command/Redis/EVAL_Test.php index 5a72c9cc..e994ecad 100644 --- a/tests/Predis/Command/Redis/EVAL_Test.php +++ b/tests/Predis/Command/Redis/EVAL_Test.php @@ -98,6 +98,20 @@ class EVAL_Test extends PredisCommandTestCase $this->assertSame($result, $redis->eval($lua, 2, 'foo', 'hoge', 'bar', 'piyo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testExecutesSpecifiedLuaScriptResp3(): void + { + $redis = $this->getResp3Client(); + + $lua = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'; + $result = ['foo', 'hoge', 'bar', 'piyo']; + + $this->assertSame($result, $redis->eval($lua, 2, 'foo', 'hoge', 'bar', 'piyo')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/EXEC_Test.php b/tests/Predis/Command/Redis/EXEC_Test.php index 5595db60..731ed6c4 100644 --- a/tests/Predis/Command/Redis/EXEC_Test.php +++ b/tests/Predis/Command/Redis/EXEC_Test.php @@ -72,6 +72,21 @@ class EXEC_Test extends PredisCommandTestCase $this->assertSame(['tx1', 'tx2'], $redis->exec()); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testExecutesTransactionAndReturnsArrayOfResponsesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->multi(); + $redis->echo('tx1'); + $redis->echo('tx2'); + + $this->assertSame(['tx1', 'tx2'], $redis->exec()); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/EXISTS_Test.php b/tests/Predis/Command/Redis/EXISTS_Test.php index e13cb6e7..d39e7aa2 100644 --- a/tests/Predis/Command/Redis/EXISTS_Test.php +++ b/tests/Predis/Command/Redis/EXISTS_Test.php @@ -104,6 +104,18 @@ class EXISTS_Test extends PredisCommandTestCase $this->assertSame(1, $redis->exists('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnValueWhenKeyExistsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $this->assertSame(1, $redis->exists('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/EXPIREAT_Test.php b/tests/Predis/Command/Redis/EXPIREAT_Test.php index cee43824..fe352d7f 100644 --- a/tests/Predis/Command/Redis/EXPIREAT_Test.php +++ b/tests/Predis/Command/Redis/EXPIREAT_Test.php @@ -88,6 +88,17 @@ class EXPIREAT_Test extends PredisCommandTestCase $this->assertSame(0, $redis->expireat('foo', 2)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsZeroOnNonExistingKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(0, $redis->expireat('foo', 2)); + } + /** * @medium * @group connected @@ -168,14 +179,14 @@ class EXPIREAT_Test extends PredisCommandTestCase 'only if new expiry is greater then current one' => [ ['newExpiryLower', 'value', 'EX', 1000], ['newExpiryGreater', 'value', 'EX', 10], - ['newExpiryGreater', time() + 20, 'GT'], - ['newExpiryLower', time() + 20, 'GT'], + ['newExpiryGreater', time() + 100, 'GT'], + ['newExpiryLower', time() + 10, 'GT'], ], 'only if new expiry is lower then current one' => [ ['newExpiryLower', 'value', 'EX', 1000], ['newExpiryGreater', 'value', 'EX', 10], - ['newExpiryLower', time() + 20, 'LT'], - ['newExpiryGreater', time() + 20, 'LT'], + ['newExpiryLower', time() + 10, 'LT'], + ['newExpiryGreater', time() + 100, 'LT'], ], ]; } diff --git a/tests/Predis/Command/Redis/EXPIRETIME_Test.php b/tests/Predis/Command/Redis/EXPIRETIME_Test.php index 4997dcd1..02f38bcd 100644 --- a/tests/Predis/Command/Redis/EXPIRETIME_Test.php +++ b/tests/Predis/Command/Redis/EXPIRETIME_Test.php @@ -74,4 +74,23 @@ class EXPIRETIME_Test extends PredisCommandTestCase $this->assertSame(-1, $redis->expiretime('key1')); $this->assertSame(-2, $redis->expiretime('non-existing key')); } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsCorrectKeyExpirationTimeResp3(): void + { + $expirationTime = (int) microtime(true) + 100000; + $redis = $this->getResp3Client(); + + $redis->set('key', 'value'); + $redis->set('key1', 'value'); + $redis->expireat('key', $expirationTime); + + $this->assertSame($expirationTime, $redis->expiretime('key')); + $this->assertSame(-1, $redis->expiretime('key1')); + $this->assertSame(-2, $redis->expiretime('non-existing key')); + } } diff --git a/tests/Predis/Command/Redis/EXPIRE_Test.php b/tests/Predis/Command/Redis/EXPIRE_Test.php index d753e421..775803f0 100644 --- a/tests/Predis/Command/Redis/EXPIRE_Test.php +++ b/tests/Predis/Command/Redis/EXPIRE_Test.php @@ -88,6 +88,17 @@ class EXPIRE_Test extends PredisCommandTestCase $this->assertSame(0, $redis->expire('foo', 2)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsZeroOnNonExistingKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(0, $redis->expire('foo', 2)); + } + /** * @medium * @group connected @@ -165,13 +176,13 @@ class EXPIRE_Test extends PredisCommandTestCase ['newExpiryLower', 'value', 'EX', 1000], ['newExpiryGreater', 'value', 'EX', 10], ['newExpiryGreater', 100, 'GT'], - ['newExpiryLower', 20, 'GT'], + ['newExpiryLower', 10, 'GT'], ], 'only if new expiry is lower then current one' => [ ['newExpiryLower', 'value', 'EX', 1000], ['newExpiryGreater', 'value', 'EX', 10], - ['newExpiryLower', 20, 'LT'], - ['newExpiryGreater', 20, 'LT'], + ['newExpiryLower', 10, 'LT'], + ['newExpiryGreater', 100, 'LT'], ], ]; } diff --git a/tests/Predis/Command/Redis/FCALL_RO_Test.php b/tests/Predis/Command/Redis/FCALL_RO_Test.php index 87a3d334..b3ecb660 100644 --- a/tests/Predis/Command/Redis/FCALL_RO_Test.php +++ b/tests/Predis/Command/Redis/FCALL_RO_Test.php @@ -81,6 +81,28 @@ class FCALL_RO_Test extends PredisCommandTestCase $this->assertSame('value', $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testInvokeGivenReadOnlyFunctionResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->set('key', 'value')); + + $this->assertSame( + self::LIB_NAME, + $redis->function->load( + "#!lua name=mylib\n redis.register_function{function_name='myfunc',callback=function(keys, args) return redis.call('GET', keys[1]) end,flags={'no-writes'}}" + ) + ); + + $actualResponse = $redis->fcall_ro('myfunc', ['key']); + $this->assertSame('value', $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/FCALL_Test.php b/tests/Predis/Command/Redis/FCALL_Test.php index 4e4ab055..548ac141 100644 --- a/tests/Predis/Command/Redis/FCALL_Test.php +++ b/tests/Predis/Command/Redis/FCALL_Test.php @@ -99,6 +99,24 @@ class FCALL_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->function->delete('mylib')); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testInvokeGivenFunctionResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame('mylib', $redis->function->load( + "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return 'hello' end)") + ); + + $actualResponse = $redis->fcall('myfunc', []); + $this->assertSame('hello', $actualResponse); + $this->assertEquals('OK', $redis->function->delete('mylib')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/FUNCTIONS_Test.php b/tests/Predis/Command/Redis/FUNCTIONS_Test.php index 49fa20ad..ad79f0ef 100644 --- a/tests/Predis/Command/Redis/FUNCTIONS_Test.php +++ b/tests/Predis/Command/Redis/FUNCTIONS_Test.php @@ -97,6 +97,24 @@ class FUNCTIONS_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->function->delete($this->libName)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testLoadFunctionAddFunctionIntoGivenLibraryResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->function->load( + "#!lua name={$this->libName} \n redis.register_function('myfunc', function(keys, args) return args[1] end)" + ); + + $this->assertSame('mylib', $actualResponse); + $this->assertSame('arg1', $redis->fcall('myfunc', [], 'arg1')); + $this->assertEquals('OK', $redis->function->delete($this->libName)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/GEOADD_Test.php b/tests/Predis/Command/Redis/GEOADD_Test.php index cb71a6f3..f7997efb 100644 --- a/tests/Predis/Command/Redis/GEOADD_Test.php +++ b/tests/Predis/Command/Redis/GEOADD_Test.php @@ -110,6 +110,19 @@ class GEOADD_Test extends PredisCommandTestCase $this->assertEquals(['Palermo' => '3479099956230698'], $redis->zrange('Sicily', 0, -1, 'WITHSCORES')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCommandFillsSortedSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo'); + + $this->assertSame([['Palermo' => 3479099956230698.0]], $redis->zrange('Sicily', 0, -1, 'WITHSCORES')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/GEODIST_Test.php b/tests/Predis/Command/Redis/GEODIST_Test.php index e940aabc..5d4af66a 100644 --- a/tests/Predis/Command/Redis/GEODIST_Test.php +++ b/tests/Predis/Command/Redis/GEODIST_Test.php @@ -92,6 +92,18 @@ class GEODIST_Test extends PredisCommandTestCase $this->assertSame('166.2742', $redis->geodist('Sicily', 'Palermo', 'Catania', 'km')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCommandReturnsGeoDistanceResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); + $this->assertSame('166.2742', $redis->geodist('Sicily', 'Palermo', 'Catania', 'km')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/GEOHASH_Test.php b/tests/Predis/Command/Redis/GEOHASH_Test.php index 04c5bf0d..33fdfa81 100644 --- a/tests/Predis/Command/Redis/GEOHASH_Test.php +++ b/tests/Predis/Command/Redis/GEOHASH_Test.php @@ -106,6 +106,18 @@ class GEOHASH_Test extends PredisCommandTestCase $this->assertSame(['sqc8b49rny0', 'sqdtr74hyu0'], $redis->geohash('Sicily', 'Palermo', 'Catania')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCommandReturnsGeoHashesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); + $this->assertSame(['sqc8b49rny0', 'sqdtr74hyu0'], $redis->geohash('Sicily', 'Palermo', 'Catania')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/GEOPOS_Test.php b/tests/Predis/Command/Redis/GEOPOS_Test.php index 02437735..1d04d85e 100644 --- a/tests/Predis/Command/Redis/GEOPOS_Test.php +++ b/tests/Predis/Command/Redis/GEOPOS_Test.php @@ -116,6 +116,21 @@ class GEOPOS_Test extends PredisCommandTestCase ], $redis->geopos('Sicily', 'Palermo', 'Catania')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCommandReturnsGeoPositionsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); + $this->assertEquals([ + ['13.36138933897018433', '38.11555639549629859'], + ['15.08726745843887329', '37.50266842333162032'], + ], $redis->geopos('Sicily', 'Palermo', 'Catania')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php b/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php index 124eb286..9a459410 100644 --- a/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php +++ b/tests/Predis/Command/Redis/GEORADIUSBYMEMBER_Test.php @@ -156,6 +156,18 @@ class GEORADIUSBYMEMBER_Test extends PredisCommandTestCase $this->assertEquals(['Agrigento', 'Palermo'], $redis->georadiusbymember('Sicily', 'Agrigento', 100, 'km')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCommandReturnsGeoRadiusInfoWithNoOptionsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania', '13.583333', '37.316667', 'Agrigento'); + $this->assertEquals(['Agrigento', 'Palermo'], $redis->georadiusbymember('Sicily', 'Agrigento', 100, 'km')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/GEORADIUS_Test.php b/tests/Predis/Command/Redis/GEORADIUS_Test.php index 063f16c7..dfb2516d 100644 --- a/tests/Predis/Command/Redis/GEORADIUS_Test.php +++ b/tests/Predis/Command/Redis/GEORADIUS_Test.php @@ -158,6 +158,18 @@ class GEORADIUS_Test extends PredisCommandTestCase $this->assertEquals(['Palermo', 'Catania'], $redis->georadius('Sicily', 15, 37, 200, 'km')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCommandReturnsGeoRadiusInfoWithNoOptionsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('Sicily', '13.361389', '38.115556', 'Palermo', '15.087269', '37.502669', 'Catania'); + $this->assertEquals(['Palermo', 'Catania'], $redis->georadius('Sicily', 15, 37, 200, 'km')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/GEOSEARCHSTORE_Test.php b/tests/Predis/Command/Redis/GEOSEARCHSTORE_Test.php index 3924cda8..b7025024 100644 --- a/tests/Predis/Command/Redis/GEOSEARCHSTORE_Test.php +++ b/tests/Predis/Command/Redis/GEOSEARCHSTORE_Test.php @@ -139,6 +139,34 @@ class GEOSEARCHSTORE_Test extends PredisCommandTestCase $this->assertSame(['member2', 'member1'], $redis->zrange('destination', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testStoresInSortedSetWithStoreDistArgumentProvidedResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('key', 1.1, 2, 'member1'); + $redis->geoadd('key', 2.1, 3, 'member2'); + $redis->geoadd('key', 3.1, 4, 'member3'); + + $actualResultingElements = $redis->geosearchstore( + 'destination', + 'key', + new FromLonLat(1, 4), + new ByRadius(9999, 'km'), + null, + 2, + false, + true + ); + + $this->assertSame(2, $actualResultingElements); + $this->assertSame(['member2', 'member1'], $redis->zrange('destination', 0, -1)); + } + /** * @group connected * @dataProvider unexpectedValuesProvider diff --git a/tests/Predis/Command/Redis/GEOSEARCH_Test.php b/tests/Predis/Command/Redis/GEOSEARCH_Test.php index ea640e00..281a83ea 100644 --- a/tests/Predis/Command/Redis/GEOSEARCH_Test.php +++ b/tests/Predis/Command/Redis/GEOSEARCH_Test.php @@ -106,6 +106,29 @@ class GEOSEARCH_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsSearchedGeospatialCoordinatesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->geoadd('key', 1.1, 2, 'member1'); + $redis->geoadd('key', 2.1, 3, 'member2'); + $redis->geoadd('key', 3.1, 4, 'member3'); + + $this->assertSame( + ['member1', 'member2', 'member3'], + $redis->geosearch( + 'key', + new FromLonLat(1, 4), + new ByRadius(9999, 'km') + ) + ); + } + /** * @group connected * @dataProvider unexpectedValuesProvider diff --git a/tests/Predis/Command/Redis/GETBIT_Test.php b/tests/Predis/Command/Redis/GETBIT_Test.php index e5d68a3f..232cb1b5 100644 --- a/tests/Predis/Command/Redis/GETBIT_Test.php +++ b/tests/Predis/Command/Redis/GETBIT_Test.php @@ -93,6 +93,22 @@ class GETBIT_Test extends PredisCommandTestCase $this->assertSame(0, $redis->getbit('key:binary', 63)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCanGetBitsFromStringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('key:binary', "\x80\x00\00\x01"); + + $this->assertSame(1, $redis->getbit('key:binary', 0)); + $this->assertSame(0, $redis->getbit('key:binary', 15)); + $this->assertSame(1, $redis->getbit('key:binary', 31)); + $this->assertSame(0, $redis->getbit('key:binary', 63)); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/GETDEL_Test.php b/tests/Predis/Command/Redis/GETDEL_Test.php index 9cf0207f..226d027c 100644 --- a/tests/Predis/Command/Redis/GETDEL_Test.php +++ b/tests/Predis/Command/Redis/GETDEL_Test.php @@ -70,4 +70,23 @@ class GETDEL_Test extends PredisCommandTestCase $this->assertSame($expectedValue, $actualResponse); $this->assertNull($redis->get($expectedKey)); } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsValueForGivenKeyAndDeleteItResp3(): void + { + $redis = $this->getResp3Client(); + $expectedKey = 'key'; + $expectedValue = 'value'; + + $redis->set($expectedKey, $expectedValue); + + $actualResponse = $redis->getdel($expectedKey); + + $this->assertSame($expectedValue, $actualResponse); + $this->assertNull($redis->get($expectedKey)); + } } diff --git a/tests/Predis/Command/Redis/GETEX_Test.php b/tests/Predis/Command/Redis/GETEX_Test.php index 893d865b..b3f8a0c2 100644 --- a/tests/Predis/Command/Redis/GETEX_Test.php +++ b/tests/Predis/Command/Redis/GETEX_Test.php @@ -79,6 +79,20 @@ class GETEX_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->getex(...$arguments)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsValueAndSetExpirationTimeForGivenKeyResp3(): void + { + $redis = $this->getClient(); + + $redis->set('key', 'value'); + + $this->assertSame('value', $redis->getex('key', '', false)); + } + /** * @group connected * @dataProvider unexpectedValuesProvider diff --git a/tests/Predis/Command/Redis/GETRANGE_Test.php b/tests/Predis/Command/Redis/GETRANGE_Test.php index 6c59b530..28680e56 100644 --- a/tests/Predis/Command/Redis/GETRANGE_Test.php +++ b/tests/Predis/Command/Redis/GETRANGE_Test.php @@ -94,6 +94,25 @@ class GETRANGE_Test extends PredisCommandTestCase $this->assertSame('', $redis->getrange('string', -1, 0)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsSubstringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('string', 'this is a string'); + + $this->assertSame('this', $redis->getrange('string', 0, 3)); + $this->assertSame('ing', $redis->getrange('string', -3, -1)); + $this->assertSame('this is a string', $redis->getrange('string', 0, -1)); + $this->assertSame('string', $redis->getrange('string', 10, 100)); + + $this->assertSame('t', $redis->getrange('string', 0, 0)); + $this->assertSame('', $redis->getrange('string', -1, 0)); + } + /** * @group connected * @requiresRedisVersion >= 2.4.0 diff --git a/tests/Predis/Command/Redis/GETSET_Test.php b/tests/Predis/Command/Redis/GETSET_Test.php index 7a910171..6605edaa 100644 --- a/tests/Predis/Command/Redis/GETSET_Test.php +++ b/tests/Predis/Command/Redis/GETSET_Test.php @@ -89,6 +89,21 @@ class GETSET_Test extends PredisCommandTestCase $this->assertSame('piyo', $redis->getset('hoge', 'piyopiyo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsPreviousValueOfKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertNull($redis->getset('foo', 'bar')); + $this->assertSame('bar', $redis->getset('foo', 'barbar')); + + $redis->set('hoge', 'piyo'); + $this->assertSame('piyo', $redis->getset('hoge', 'piyopiyo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/GET_Test.php b/tests/Predis/Command/Redis/GET_Test.php index 5e73e6d1..c4a22a5b 100644 --- a/tests/Predis/Command/Redis/GET_Test.php +++ b/tests/Predis/Command/Redis/GET_Test.php @@ -86,6 +86,18 @@ class GET_Test extends PredisCommandTestCase $this->assertEquals('bar', $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsStringValueResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->set('foo', 'bar')); + $this->assertEquals('bar', $redis->get('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/HDEL_Test.php b/tests/Predis/Command/Redis/HDEL_Test.php index 80f1d477..11a49345 100644 --- a/tests/Predis/Command/Redis/HDEL_Test.php +++ b/tests/Predis/Command/Redis/HDEL_Test.php @@ -104,6 +104,21 @@ class HDEL_Test extends PredisCommandTestCase $this->assertSame(0, $redis->hdel('unknown', 'foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testDeletesSpecifiedFieldsFromHashResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut'); + + $this->assertSame(2, $redis->hdel('metavars', 'foo', 'hoge')); + $this->assertSame(0, $redis->hdel('metavars', 'foofoo')); + $this->assertSame(0, $redis->hdel('unknown', 'foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HEXISTS_Test.php b/tests/Predis/Command/Redis/HEXISTS_Test.php index 303abd73..6e04dc62 100644 --- a/tests/Predis/Command/Redis/HEXISTS_Test.php +++ b/tests/Predis/Command/Redis/HEXISTS_Test.php @@ -93,6 +93,21 @@ class HEXISTS_Test extends PredisCommandTestCase $this->assertSame(0, $redis->hexists('unknown', 'foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsExistenceOfSpecifiedFieldResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo'); + + $this->assertSame(1, $redis->hexists('metavars', 'foo')); + $this->assertSame(0, $redis->hexists('metavars', 'lol')); + $this->assertSame(0, $redis->hexists('unknown', 'foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HGETALL_Test.php b/tests/Predis/Command/Redis/HGETALL_Test.php index 79529430..12b75e95 100644 --- a/tests/Predis/Command/Redis/HGETALL_Test.php +++ b/tests/Predis/Command/Redis/HGETALL_Test.php @@ -94,6 +94,20 @@ class HGETALL_Test extends PredisCommandTestCase $this->assertSame([], $redis->hgetall('unknown')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsAllTheFieldsAndTheirValuesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut'); + + $this->assertSame(['foo' => 'bar', 'hoge' => 'piyo', 'lol' => 'wut'], $redis->hgetall('metavars')); + $this->assertSame([], $redis->hgetall('unknown')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HGET_Test.php b/tests/Predis/Command/Redis/HGET_Test.php index cbe1704b..7e498bcf 100644 --- a/tests/Predis/Command/Redis/HGET_Test.php +++ b/tests/Predis/Command/Redis/HGET_Test.php @@ -90,6 +90,21 @@ class HGET_Test extends PredisCommandTestCase $this->assertNull($redis->hget('unknown', 'foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsValueOfSpecifiedFieldResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo'); + + $this->assertSame('bar', $redis->hget('metavars', 'foo')); + $this->assertNull($redis->hget('metavars', 'lol')); + $this->assertNull($redis->hget('unknown', 'foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php b/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php index 1c3c2665..9fdde0f6 100644 --- a/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php +++ b/tests/Predis/Command/Redis/HINCRBYFLOAT_Test.php @@ -91,6 +91,22 @@ class HINCRBYFLOAT_Test extends PredisCommandTestCase $this->assertSame(['foo' => '10.5', 'hoge' => '11'], $redis->hgetall('metavars')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testIncrementsValueOfFieldByFloatResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame('10.5', $redis->hincrbyfloat('metavars', 'foo', 10.5)); + + $redis->hincrbyfloat('metavars', 'hoge', 10.001); + $this->assertSame('11', $redis->hincrbyfloat('metavars', 'hoge', 0.999)); + + $this->assertSame(['foo' => '10.5', 'hoge' => '11'], $redis->hgetall('metavars')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/HINCRBY_Test.php b/tests/Predis/Command/Redis/HINCRBY_Test.php index 2fc33986..0a64def6 100644 --- a/tests/Predis/Command/Redis/HINCRBY_Test.php +++ b/tests/Predis/Command/Redis/HINCRBY_Test.php @@ -89,6 +89,20 @@ class HINCRBY_Test extends PredisCommandTestCase $this->assertSame(['foo' => '10', 'hoge' => '15'], $redis->hgetall('metavars')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testIncrementsValueOfFieldByIntegerResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(10, $redis->hincrby('metavars', 'foo', 10)); + $this->assertSame(5, $redis->hincrby('metavars', 'hoge', 5)); + $this->assertSame(15, $redis->hincrby('metavars', 'hoge', 10)); + $this->assertSame(['foo' => '10', 'hoge' => '15'], $redis->hgetall('metavars')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HKEYS_Test.php b/tests/Predis/Command/Redis/HKEYS_Test.php index 1d0cfaf0..091dc171 100644 --- a/tests/Predis/Command/Redis/HKEYS_Test.php +++ b/tests/Predis/Command/Redis/HKEYS_Test.php @@ -94,6 +94,20 @@ class HKEYS_Test extends PredisCommandTestCase $this->assertSame([], $redis->hkeys('unknown')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsKeysOfHashResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut'); + + $this->assertSame(['foo', 'hoge', 'lol'], $redis->hkeys('metavars')); + $this->assertSame([], $redis->hkeys('unknown')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HLEN_Test.php b/tests/Predis/Command/Redis/HLEN_Test.php index ad3d674c..af0e99ab 100644 --- a/tests/Predis/Command/Redis/HLEN_Test.php +++ b/tests/Predis/Command/Redis/HLEN_Test.php @@ -89,6 +89,20 @@ class HLEN_Test extends PredisCommandTestCase $this->assertSame(0, $redis->hlen('unknown')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsLengthOfHashResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut'); + + $this->assertSame(3, $redis->hlen('metavars')); + $this->assertSame(0, $redis->hlen('unknown')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HMGET_Test.php b/tests/Predis/Command/Redis/HMGET_Test.php index 54a9d015..4c2aed03 100644 --- a/tests/Predis/Command/Redis/HMGET_Test.php +++ b/tests/Predis/Command/Redis/HMGET_Test.php @@ -134,6 +134,22 @@ class HMGET_Test extends PredisCommandTestCase $this->assertSame([null, null], $redis->hmget('unknown', 'foo', 'hoge')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsValuesOfSpecifiedFieldsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut'); + + $this->assertSame(['bar', 'piyo', null], $redis->hmget('metavars', 'foo', 'hoge', 'unknown')); + $this->assertSame(['bar', 'bar'], $redis->hmget('metavars', 'foo', 'foo')); + $this->assertSame([null, null], $redis->hmget('metavars', 'unknown', 'unknown')); + $this->assertSame([null, null], $redis->hmget('unknown', 'foo', 'hoge')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HMSET_Test.php b/tests/Predis/Command/Redis/HMSET_Test.php index 91c6046a..6a2aeb50 100644 --- a/tests/Predis/Command/Redis/HMSET_Test.php +++ b/tests/Predis/Command/Redis/HMSET_Test.php @@ -104,6 +104,21 @@ class HMSET_Test extends PredisCommandTestCase $this->assertSame(['foo' => 'barbar', 'hoge' => 'piyo', 'lol' => 'wut'], $redis->hgetall('metavars')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testSetsSpecifiedFieldsOfHashResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo')); + $this->assertSame(['foo' => 'bar', 'hoge' => 'piyo'], $redis->hgetall('metavars')); + + $this->assertEquals('OK', $redis->hmset('metavars', 'foo', 'barbar', 'lol', 'wut')); + $this->assertSame(['foo' => 'barbar', 'hoge' => 'piyo', 'lol' => 'wut'], $redis->hgetall('metavars')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HRANDFIELD_Test.php b/tests/Predis/Command/Redis/HRANDFIELD_Test.php index e706e47a..f6af170e 100644 --- a/tests/Predis/Command/Redis/HRANDFIELD_Test.php +++ b/tests/Predis/Command/Redis/HRANDFIELD_Test.php @@ -81,6 +81,21 @@ class HRANDFIELD_Test extends PredisCommandTestCase $this->assertOneOf($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsRandomFieldsFromHashResp3(): void + { + $redis = $this->getClient(); + + $redis->hset('key', 'key1', 'value1', 'key2', 'value2', 'key3', 'value3'); + $actualResponse = $redis->hrandfield('key'); + + $this->assertOneOf(['key1', 'key2', 'key3'], $actualResponse); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Command/Redis/HSCAN_Test.php b/tests/Predis/Command/Redis/HSCAN_Test.php index e0c07a4a..15b1c1d5 100644 --- a/tests/Predis/Command/Redis/HSCAN_Test.php +++ b/tests/Predis/Command/Redis/HSCAN_Test.php @@ -127,6 +127,25 @@ class HSCAN_Test extends PredisCommandTestCase $this->assertSame($expectedValues, array_values($response[1])); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testScanWithoutMatchResp3(): void + { + $expectedFields = ['field:one', 'field:two', 'field:three', 'field:four']; + $expectedValues = ['one', 'two', 'three', 'four']; + + $redis = $this->getResp3Client(); + $redis->hmset('key', array_combine($expectedFields, $expectedValues)); + + $response = $redis->hscan('key', 0); + + $this->assertSame('0', $response[0]); + $this->assertSame($expectedFields, array_keys($response[1])); + $this->assertSame($expectedValues, array_values($response[1])); + } + /** * @group connected * @requiresRedisVersion >= 2.8.0 diff --git a/tests/Predis/Command/Redis/HSETNX_Test.php b/tests/Predis/Command/Redis/HSETNX_Test.php index 051631d2..7bc27917 100644 --- a/tests/Predis/Command/Redis/HSETNX_Test.php +++ b/tests/Predis/Command/Redis/HSETNX_Test.php @@ -93,6 +93,21 @@ class HSETNX_Test extends PredisCommandTestCase $this->assertSame(['bar', 'piyo'], $redis->hmget('metavars', 'foo', 'hoge')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testSetsNewFieldsAndPreserversExistingOnesResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->hsetnx('metavars', 'foo', 'bar')); + $this->assertSame(1, $redis->hsetnx('metavars', 'hoge', 'piyo')); + $this->assertSame(0, $redis->hsetnx('metavars', 'foo', 'barbar')); + + $this->assertSame(['bar', 'piyo'], $redis->hmget('metavars', 'foo', 'hoge')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HSET_Test.php b/tests/Predis/Command/Redis/HSET_Test.php index 940420da..ffcdd174 100644 --- a/tests/Predis/Command/Redis/HSET_Test.php +++ b/tests/Predis/Command/Redis/HSET_Test.php @@ -92,6 +92,20 @@ class HSET_Test extends PredisCommandTestCase $this->assertSame(['bar', 'piyo'], $redis->hmget('metavars', 'foo', 'hoge')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testSetsValueOfSpecifiedFieldResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->hset('metavars', 'foo', 'bar')); + $this->assertSame(1, $redis->hset('metavars', 'hoge', 'piyo')); + + $this->assertSame(['bar', 'piyo'], $redis->hmget('metavars', 'foo', 'hoge')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/HSTRLEN_Test.php b/tests/Predis/Command/Redis/HSTRLEN_Test.php index 4b1270b2..78273e79 100644 --- a/tests/Predis/Command/Redis/HSTRLEN_Test.php +++ b/tests/Predis/Command/Redis/HSTRLEN_Test.php @@ -100,6 +100,27 @@ class HSTRLEN_Test extends PredisCommandTestCase $this->assertSame(0, $redis->hstrlen('unknown', 'foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsStringLengthOfSpecifiedFieldResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo'); + + // Existing key and field + $this->assertSame(3, $redis->hstrlen('metavars', 'foo')); + $this->assertSame(4, $redis->hstrlen('metavars', 'hoge')); + + // Existing key but non existing field + $this->assertSame(0, $redis->hstrlen('metavars', 'foofoo')); + + // Non existing key + $this->assertSame(0, $redis->hstrlen('unknown', 'foo')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/HVALS_Test.php b/tests/Predis/Command/Redis/HVALS_Test.php index f7ece31b..919ce794 100644 --- a/tests/Predis/Command/Redis/HVALS_Test.php +++ b/tests/Predis/Command/Redis/HVALS_Test.php @@ -94,6 +94,20 @@ class HVALS_Test extends PredisCommandTestCase $this->assertSame([], $redis->hvals('unknown')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsValuesOfHashResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo', 'lol', 'wut'); + + $this->assertSame(['bar', 'piyo', 'wut'], $redis->hvals('metavars')); + $this->assertSame([], $redis->hvals('unknown')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php b/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php index e59797f8..f880bfd6 100644 --- a/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php +++ b/tests/Predis/Command/Redis/INCRBYFLOAT_Test.php @@ -87,6 +87,18 @@ class INCRBYFLOAT_Test extends PredisCommandTestCase $this->assertEquals(10.5, $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals(10.5, $redis->incrbyfloat('foo', 10.5)); + $this->assertEquals(10.5, $redis->get('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/INCRBY_Test.php b/tests/Predis/Command/Redis/INCRBY_Test.php index 319cc870..ea3d04f7 100644 --- a/tests/Predis/Command/Redis/INCRBY_Test.php +++ b/tests/Predis/Command/Redis/INCRBY_Test.php @@ -86,6 +86,18 @@ class INCRBY_Test extends PredisCommandTestCase $this->assertEquals(10, $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(10, $redis->incrby('foo', 10)); + $this->assertEquals(10, $redis->get('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/INCR_Test.php b/tests/Predis/Command/Redis/INCR_Test.php index e3ebc6d6..d610cf4b 100644 --- a/tests/Predis/Command/Redis/INCR_Test.php +++ b/tests/Predis/Command/Redis/INCR_Test.php @@ -86,6 +86,18 @@ class INCR_Test extends PredisCommandTestCase $this->assertEquals(1, $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->incr('foo')); + $this->assertEquals(1, $redis->get('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/INFO_Test.php b/tests/Predis/Command/Redis/INFO_Test.php index 9ad12749..4bd7d8f1 100644 --- a/tests/Predis/Command/Redis/INFO_Test.php +++ b/tests/Predis/Command/Redis/INFO_Test.php @@ -313,6 +313,19 @@ BUFFER; $this->assertArrayHasKey('redis_version', $info['Server'] ?? $info); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsAnArrayOfInfoResp3(): void + { + $redis = $this->getResp3Client(); + $command = $this->getCommand(); + + $this->assertIsArray($info = $redis->executeCommand($command)); + $this->assertArrayHasKey('redis_version', $info['Server'] ?? $info); + } + /** * @group connected * @requiresRedisVersion < 2.6.0 diff --git a/tests/Predis/Command/Redis/Json/JSONARRAPPEND_Test.php b/tests/Predis/Command/Redis/Json/JSONARRAPPEND_Test.php index 67846355..0f4292c2 100644 --- a/tests/Predis/Command/Redis/Json/JSONARRAPPEND_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONARRAPPEND_Test.php @@ -88,6 +88,23 @@ class JSONARRAPPEND_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testAppendItemsToGivenJsonArrayResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":["value1","value2"]}'); + + $actualResponse = $redis->jsonarrappend('key', '$.key2', '"value3"'); + + $this->assertSame([3], $actualResponse); + $this->assertSame([['{"key1":"value1","key2":["value1","value2","value3"]}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONARRINDEX_Test.php b/tests/Predis/Command/Redis/Json/JSONARRINDEX_Test.php index 43e91ca4..938b4d69 100644 --- a/tests/Predis/Command/Redis/Json/JSONARRINDEX_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONARRINDEX_Test.php @@ -86,6 +86,19 @@ class JSONARRINDEX_Test extends PredisCommandTestCase $this->assertSame($expectedIndices, $redis->jsonarrindex($key, $path, $value, $start, $stop)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnsCorrectJsonArrayIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":["value1","value2"]}'); + $this->assertSame([1], $redis->jsonarrindex('key', '$.key2', '"value2"')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONARRINSERT_Test.php b/tests/Predis/Command/Redis/Json/JSONARRINSERT_Test.php index 5bb2c758..9309e0a7 100644 --- a/tests/Predis/Command/Redis/Json/JSONARRINSERT_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONARRINSERT_Test.php @@ -90,6 +90,23 @@ class JSONARRINSERT_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedArray, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testInsertElementIntoJsonArrayBeforeGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":["value1","value3"]}'); + + $actualResponse = $redis->jsonarrinsert('key', '$.key2', 1, '"value2"'); + + $this->assertSame([3], $actualResponse); + $this->assertSame([['{"key1":"value1","key2":["value1","value2","value3"]}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONARRLEN_Test.php b/tests/Predis/Command/Redis/Json/JSONARRLEN_Test.php index 6565e347..65912ff5 100644 --- a/tests/Predis/Command/Redis/Json/JSONARRLEN_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONARRLEN_Test.php @@ -81,6 +81,20 @@ class JSONARRLEN_Test extends PredisCommandTestCase $this->assertSame($expectedLength, $redis->jsonarrlen($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnsCorrectJsonArrayLengthResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":["value1","value2"]}'); + + $this->assertSame([2], $redis->jsonarrlen('key', '$.key2')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONARRPOP_Test.php b/tests/Predis/Command/Redis/Json/JSONARRPOP_Test.php index 6d80fd99..089da648 100644 --- a/tests/Predis/Command/Redis/Json/JSONARRPOP_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONARRPOP_Test.php @@ -87,6 +87,22 @@ class JSONARRPOP_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testRemovesElementFromIndexOfJsonArrayResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":["value1","value2"]}'); + $actualResponse = $redis->jsonarrpop('key', '$.key2', -1); + + $this->assertSame(['"value2"'], $actualResponse); + $this->assertSame([['{"key1":"value1","key2":["value1"]}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONARRTRIM_Test.php b/tests/Predis/Command/Redis/Json/JSONARRTRIM_Test.php index a40de6a0..f032303c 100644 --- a/tests/Predis/Command/Redis/Json/JSONARRTRIM_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONARRTRIM_Test.php @@ -89,6 +89,22 @@ class JSONARRTRIM_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testCorrectlyTrimGivenJsonArrayResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":[1,2,3,4,5,6]}'); + $actualResponse = $redis->jsonarrtrim('key', '$.key2', 1, 4); + + $this->assertSame([4], $actualResponse); + $this->assertSame([['{"key1":"value1","key2":[2,3,4,5]}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONCLEAR_Test.php b/tests/Predis/Command/Redis/Json/JSONCLEAR_Test.php index 5e53cfa6..e2fb9888 100644 --- a/tests/Predis/Command/Redis/Json/JSONCLEAR_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONCLEAR_Test.php @@ -85,6 +85,22 @@ class JSONCLEAR_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testClearValuesOnArraysAndObjectsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":[1,2,3,4,5,6]}'); + $actualResponse = $redis->jsonclear('key', '$.key2'); + + $this->assertSame(1, $actualResponse); + $this->assertSame([['{"key1":"value1","key2":[]}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONDEBUG_Test.php b/tests/Predis/Command/Redis/Json/JSONDEBUG_Test.php index b13feec9..85dae459 100644 --- a/tests/Predis/Command/Redis/Json/JSONDEBUG_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONDEBUG_Test.php @@ -75,6 +75,20 @@ class JSONDEBUG_Test extends PredisCommandTestCase $this->assertGreaterThan(0, $redis->jsondebug->memory($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testMemoryReturnsCorrectMemoryUsageAboutJsonResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + + $this->assertGreaterThan(0, $redis->jsondebug->memory('key', '$')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Json/JSONDEL_Test.php b/tests/Predis/Command/Redis/Json/JSONDEL_Test.php index 4d48d82f..1c948666 100644 --- a/tests/Predis/Command/Redis/Json/JSONDEL_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONDEL_Test.php @@ -85,6 +85,22 @@ class JSONDEL_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testDeletesPathsAtKeyFromGivenJsonStringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + $actualResponse = $redis->jsondel('key', '$.key2'); + + $this->assertSame(1, $actualResponse); + $this->assertSame([['{"key1":"value1"}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONFORGET_Test.php b/tests/Predis/Command/Redis/Json/JSONFORGET_Test.php index 9e5ef474..fd089739 100644 --- a/tests/Predis/Command/Redis/Json/JSONFORGET_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONFORGET_Test.php @@ -85,6 +85,22 @@ class JSONFORGET_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testDeletesPathsAtKeyFromGivenJsonStringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + $actualResponse = $redis->jsonforget('key', '$.key2'); + + $this->assertSame(1, $actualResponse); + $this->assertSame([['{"key1":"value1"}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONGET_Test.php b/tests/Predis/Command/Redis/Json/JSONGET_Test.php index 39c6cea8..47142d06 100644 --- a/tests/Predis/Command/Redis/Json/JSONGET_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONGET_Test.php @@ -83,6 +83,22 @@ class JSONGET_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->jsonget($key, $indent, $newline, $space)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testReturnsCorrectJsonResponseResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + $this->assertSame( + [['{"key1":"value1","key2":"value2"}']], + $redis->jsonget('key') + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Json/JSONMGET_Test.php b/tests/Predis/Command/Redis/Json/JSONMGET_Test.php index 5700bfee..92c5ce51 100644 --- a/tests/Predis/Command/Redis/Json/JSONMGET_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONMGET_Test.php @@ -84,6 +84,21 @@ class JSONMGET_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->jsonmget($keys, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testMGetReturnsMultipleKeysArgumentsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key1', '$', '{"key1":"value1","key2":"value2"}'); + $redis->jsonset('key2', '$', '{"key1":"value3","key2":"value2"}'); + + $this->assertSame(['["value1"]', '["value3"]'], $redis->jsonmget(['key1', 'key2'], '$.key1')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONNUMINCRBY_Test.php b/tests/Predis/Command/Redis/Json/JSONNUMINCRBY_Test.php index 3dc87189..d3b547ce 100644 --- a/tests/Predis/Command/Redis/Json/JSONNUMINCRBY_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONNUMINCRBY_Test.php @@ -83,6 +83,20 @@ class JSONNUMINCRBY_Test extends PredisCommandTestCase $this->assertSame($expectedIncrementedResponse, $redis->jsonnumincrby($key, $path, $value)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testIncrementJsonNumericOnGivenValueResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":1}'); + + $this->assertSame([2], $redis->jsonnumincrby('key', '$.key2', 1)); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONOBJKEYS_Test.php b/tests/Predis/Command/Redis/Json/JSONOBJKEYS_Test.php index 5726e9a1..a14dd300 100644 --- a/tests/Predis/Command/Redis/Json/JSONOBJKEYS_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONOBJKEYS_Test.php @@ -81,6 +81,20 @@ class JSONOBJKEYS_Test extends PredisCommandTestCase $this->assertSame($expectedKeys, $redis->jsonobjkeys($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnsKeysForGivenJsonObjectResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + + $this->assertSame(['key1', 'key2'], $redis->jsonobjkeys('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONOBJLEN_Test.php b/tests/Predis/Command/Redis/Json/JSONOBJLEN_Test.php index 0380bc93..ad16e9a8 100644 --- a/tests/Predis/Command/Redis/Json/JSONOBJLEN_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONOBJLEN_Test.php @@ -81,6 +81,20 @@ class JSONOBJLEN_Test extends PredisCommandTestCase $this->assertSame($expectedObjectLength, $redis->jsonobjlen($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnsLengthOfGivenJsonObjectResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + + $this->assertSame(2, $redis->jsonobjlen('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONRESP_Test.php b/tests/Predis/Command/Redis/Json/JSONRESP_Test.php index 5fa15aaf..72a2e575 100644 --- a/tests/Predis/Command/Redis/Json/JSONRESP_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONRESP_Test.php @@ -82,6 +82,20 @@ class JSONRESP_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $redis->jsonresp($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnRespValueFromGivenJsonResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1"}'); + + $this->assertEquals(['value1'], $redis->jsonresp('key', '$.key1')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONSET_Test.php b/tests/Predis/Command/Redis/Json/JSONSET_Test.php index dc1715f8..92b1b696 100644 --- a/tests/Predis/Command/Redis/Json/JSONSET_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONSET_Test.php @@ -86,6 +86,20 @@ class JSONSET_Test extends PredisCommandTestCase $this->assertSame($expectedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testSetCorrectJsonValueAndReturnsCorrespondingResponseResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}')); + $this->assertEquals('OK', $redis->jsonset('key', '$', '{"key3":"value3"}')); + $this->assertSame([['{"key3":"value3"}']], $redis->jsonget('key')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Json/JSONSTRAPPEND_Test.php b/tests/Predis/Command/Redis/Json/JSONSTRAPPEND_Test.php index 3f2b1e32..3aa5d97f 100644 --- a/tests/Predis/Command/Redis/Json/JSONSTRAPPEND_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONSTRAPPEND_Test.php @@ -87,6 +87,22 @@ class JSONSTRAPPEND_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testAppendStringToExistingJsonStringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + $actualResponse = $redis->jsonstrappend('key', '$.key2', '"foo"'); + + $this->assertSame([9], $actualResponse); + $this->assertSame([['{"key1":"value1","key2":"value2foo"}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONSTRLEN_Test.php b/tests/Predis/Command/Redis/Json/JSONSTRLEN_Test.php index 4058d89a..2f98241a 100644 --- a/tests/Predis/Command/Redis/Json/JSONSTRLEN_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONSTRLEN_Test.php @@ -81,6 +81,20 @@ class JSONSTRLEN_Test extends PredisCommandTestCase $this->assertSame($expectedStringLength, $redis->jsonstrlen($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 1.0.0 + */ + public function testReturnsLengthOfGivenJsonStringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); + + $this->assertSame([6], $redis->jsonstrlen('key', '$.key2')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONTOGGLE_Test.php b/tests/Predis/Command/Redis/Json/JSONTOGGLE_Test.php index 40dc8950..207fa14a 100644 --- a/tests/Predis/Command/Redis/Json/JSONTOGGLE_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONTOGGLE_Test.php @@ -85,6 +85,22 @@ class JSONTOGGLE_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testToggleChangesBooleanValueToOppositeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":true}'); + $actualResponse = $redis->jsontoggle('key', '$.key1'); + + $this->assertSame([0], $actualResponse); + $this->assertSame([['{"key1":false}']], $redis->jsonget('key')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Json/JSONTYPE_Test.php b/tests/Predis/Command/Redis/Json/JSONTYPE_Test.php index f40d4e13..262b8ab6 100644 --- a/tests/Predis/Command/Redis/Json/JSONTYPE_Test.php +++ b/tests/Predis/Command/Redis/Json/JSONTYPE_Test.php @@ -81,6 +81,20 @@ class JSONTYPE_Test extends PredisCommandTestCase $this->assertSame($expectedType, $redis->jsontype($key, $path)); } + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.1 + */ + public function testReturnsJsonValueTypeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->jsonset('key', '$', '{"key1":"value1"}'); + + $this->assertSame([['string']], $redis->jsontype('key', '$.key1')); + } + public function jsonProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/KEYS_Test.php b/tests/Predis/Command/Redis/KEYS_Test.php index 2a9f63ec..0d0a8171 100644 --- a/tests/Predis/Command/Redis/KEYS_Test.php +++ b/tests/Predis/Command/Redis/KEYS_Test.php @@ -95,4 +95,23 @@ class KEYS_Test extends PredisCommandTestCase $this->assertSameValues(array_keys($keysAll), $redis->keys('*')); $this->assertSameValues(array_keys($keys), $redis->keys('a?a')); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsArrayOfMatchingKeysResp3(): void + { + $keys = ['aaa' => 1, 'aba' => 2, 'aca' => 3]; + $keysNS = ['metavar:foo' => 'bar', 'metavar:hoge' => 'piyo']; + $keysAll = array_merge($keys, $keysNS); + + $redis = $this->getResp3Client(); + $redis->mset($keysAll); + + $this->assertSame([], $redis->keys('nomatch:*')); + $this->assertSameValues(array_keys($keysNS), $redis->keys('metavar:*')); + $this->assertSameValues(array_keys($keysAll), $redis->keys('*')); + $this->assertSameValues(array_keys($keys), $redis->keys('a?a')); + } } diff --git a/tests/Predis/Command/Redis/LASTSAVE_Test.php b/tests/Predis/Command/Redis/LASTSAVE_Test.php index 7ced5e96..ed36b41c 100644 --- a/tests/Predis/Command/Redis/LASTSAVE_Test.php +++ b/tests/Predis/Command/Redis/LASTSAVE_Test.php @@ -62,4 +62,15 @@ class LASTSAVE_Test extends PredisCommandTestCase $this->assertIsInt($redis->lastsave()); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsIntegerValueResp3(): void + { + $redis = $this->getClient(); + + $this->assertIsInt($redis->lastsave()); + } } diff --git a/tests/Predis/Command/Redis/LCS_Test.php b/tests/Predis/Command/Redis/LCS_Test.php index 72cb5c6c..f661f597 100644 --- a/tests/Predis/Command/Redis/LCS_Test.php +++ b/tests/Predis/Command/Redis/LCS_Test.php @@ -76,6 +76,20 @@ class LCS_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->lcs(...$functionArguments)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsLongestCommonSubsequenceFromGivenStringsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->mset('key1', 'value1', 'key2', '2value'); + + $this->assertSame('value', $redis->lcs('key1', 'key2')); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/LINDEX_Test.php b/tests/Predis/Command/Redis/LINDEX_Test.php index 10b491a4..6a4f572e 100644 --- a/tests/Predis/Command/Redis/LINDEX_Test.php +++ b/tests/Predis/Command/Redis/LINDEX_Test.php @@ -89,6 +89,21 @@ class LINDEX_Test extends PredisCommandTestCase $this->assertNull($redis->lindex('letters', 100)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementAtIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e'); + + $this->assertSame('a', $redis->lindex('letters', 0)); + $this->assertSame('c', $redis->lindex('letters', 2)); + $this->assertNull($redis->lindex('letters', 100)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LINSERT_Test.php b/tests/Predis/Command/Redis/LINSERT_Test.php index 103b7993..e5b2feeb 100644 --- a/tests/Predis/Command/Redis/LINSERT_Test.php +++ b/tests/Predis/Command/Redis/LINSERT_Test.php @@ -89,6 +89,21 @@ class LINSERT_Test extends PredisCommandTestCase $this->assertSame(['a', 'b', 'c', 'd', 'e'], $redis->lrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsLengthOfListAfterInsertResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'c', 'e'); + + $this->assertSame(4, $redis->linsert('letters', 'before', 'c', 'b')); + $this->assertSame(5, $redis->linsert('letters', 'after', 'c', 'd')); + $this->assertSame(['a', 'b', 'c', 'd', 'e'], $redis->lrange('letters', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LLEN_Test.php b/tests/Predis/Command/Redis/LLEN_Test.php index 14d9d25f..ad60f29b 100644 --- a/tests/Predis/Command/Redis/LLEN_Test.php +++ b/tests/Predis/Command/Redis/LLEN_Test.php @@ -90,6 +90,21 @@ class LLEN_Test extends PredisCommandTestCase $this->assertSame(6, $redis->llen('letters')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsLengthOfListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c'); + $this->assertSame(3, $redis->llen('letters')); + + $redis->rpush('letters', 'd', 'e', 'f'); + $this->assertSame(6, $redis->llen('letters')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/LMOVE_Test.php b/tests/Predis/Command/Redis/LMOVE_Test.php index 7a105bad..c7fc255a 100644 --- a/tests/Predis/Command/Redis/LMOVE_Test.php +++ b/tests/Predis/Command/Redis/LMOVE_Test.php @@ -92,6 +92,25 @@ class LMOVE_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedSecondList, $redis->lrange('test-lmove2', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsCorrectListElementResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('test-lmove1', 'element1', 'element2', 'element3'); + $redis->rpush('test-lmove2', 'element4', 'element5', 'element6'); + + $actualResponse = $redis->lmove('test-lmove1', 'test-lmove2', 'LEFT', 'LEFT'); + + $this->assertSame('element1', $actualResponse); + $this->assertSame(['element2', 'element3'], $redis->lrange('test-lmove1', 0, -1)); + $this->assertSame(['element1', 'element4', 'element5', 'element6'], $redis->lrange('test-lmove2', 0, -1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/LMPOP_Test.php b/tests/Predis/Command/Redis/LMPOP_Test.php index bbcd68b8..f35f44ce 100644 --- a/tests/Predis/Command/Redis/LMPOP_Test.php +++ b/tests/Predis/Command/Redis/LMPOP_Test.php @@ -88,6 +88,22 @@ class LMPOP_Test extends PredisCommandTestCase $this->assertSame($expectedModifiedList, $redis->lrange($key, 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testPopElementsFromGivenListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->lpush('key', 'elem1', 'elem2', 'elem3'); + $actualResponse = $redis->lmpop(['key1', 'key']); + + $this->assertSame(['key' => ['elem3']], $actualResponse); + $this->assertSame(['elem2', 'elem1'], $redis->lrange('key', 0, -1)); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/LPOP_Test.php b/tests/Predis/Command/Redis/LPOP_Test.php index 38d5cfff..3c86d483 100644 --- a/tests/Predis/Command/Redis/LPOP_Test.php +++ b/tests/Predis/Command/Redis/LPOP_Test.php @@ -89,6 +89,21 @@ class LPOP_Test extends PredisCommandTestCase $this->assertSame(['c', 'd'], $redis->lrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPopsTheFirstElementFromListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c', 'd'); + + $this->assertSame('a', $redis->lpop('letters')); + $this->assertSame('b', $redis->lpop('letters')); + $this->assertSame(['c', 'd'], $redis->lrange('letters', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LPUSHX_Test.php b/tests/Predis/Command/Redis/LPUSHX_Test.php index c36e81da..0fef0f7b 100644 --- a/tests/Predis/Command/Redis/LPUSHX_Test.php +++ b/tests/Predis/Command/Redis/LPUSHX_Test.php @@ -89,6 +89,20 @@ class LPUSHX_Test extends PredisCommandTestCase $this->assertSame(['hoge', 'foo'], $redis->lrange('metavars', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPushesElementsToHeadOfExistingListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->lpush('metavars', 'foo'); + + $this->assertSame(2, $redis->lpushx('metavars', 'hoge')); + $this->assertSame(['hoge', 'foo'], $redis->lrange('metavars', 0, -1)); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/LPUSH_Test.php b/tests/Predis/Command/Redis/LPUSH_Test.php index db90860f..9dbe5995 100644 --- a/tests/Predis/Command/Redis/LPUSH_Test.php +++ b/tests/Predis/Command/Redis/LPUSH_Test.php @@ -102,6 +102,20 @@ class LPUSH_Test extends PredisCommandTestCase $this->assertSame(['hoge', 'foo'], $redis->lrange('metavars', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPushesElementsToHeadOfListResp3(): void + { + $redis = $this->getResp3Client(); + + // NOTE: List push operations return the list length since Redis commit 520b5a3 + $this->assertSame(1, $redis->lpush('metavars', 'foo')); + $this->assertSame(2, $redis->lpush('metavars', 'hoge')); + $this->assertSame(['hoge', 'foo'], $redis->lrange('metavars', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LRANGE_Test.php b/tests/Predis/Command/Redis/LRANGE_Test.php index eae80582..4148d779 100644 --- a/tests/Predis/Command/Redis/LRANGE_Test.php +++ b/tests/Predis/Command/Redis/LRANGE_Test.php @@ -95,6 +95,22 @@ class LRANGE_Test extends PredisCommandTestCase $this->assertSame(['a'], $redis->lrange('letters', 0, 0)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsListSliceWithPositiveStartAndStopResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); + + $this->assertSame(['a', 'b', 'c', 'd'], $redis->lrange('letters', 0, 3)); + $this->assertSame(['e', 'f', 'g', 'h'], $redis->lrange('letters', 4, 7)); + $this->assertSame(['a', 'b'], $redis->lrange('letters', 0, 1)); + $this->assertSame(['a'], $redis->lrange('letters', 0, 0)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LREM_Test.php b/tests/Predis/Command/Redis/LREM_Test.php index 5a70eab6..a861022f 100644 --- a/tests/Predis/Command/Redis/LREM_Test.php +++ b/tests/Predis/Command/Redis/LREM_Test.php @@ -88,6 +88,20 @@ class LREM_Test extends PredisCommandTestCase $this->assertSame(['a', 'b', 'c', '_', 'd', '_'], $redis->lrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesMatchingElementsFromHeadToTailResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', '_', 'b', '_', 'c', '_', 'd', '_'); + + $this->assertSame(2, $redis->lrem('letters', 2, '_')); + $this->assertSame(['a', 'b', 'c', '_', 'd', '_'], $redis->lrange('letters', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LSET_Test.php b/tests/Predis/Command/Redis/LSET_Test.php index 200ff67a..f9801fab 100644 --- a/tests/Predis/Command/Redis/LSET_Test.php +++ b/tests/Predis/Command/Redis/LSET_Test.php @@ -88,6 +88,20 @@ class LSET_Test extends PredisCommandTestCase $this->assertSame(['a', 'B', 'c'], $redis->lrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testSetsElementAtSpecifiedIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c'); + + $this->assertEquals('OK', $redis->lset('letters', 1, 'B')); + $this->assertSame(['a', 'B', 'c'], $redis->lrange('letters', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/LTRIM_Test.php b/tests/Predis/Command/Redis/LTRIM_Test.php index 7c5c16cc..d7ca0f0c 100644 --- a/tests/Predis/Command/Redis/LTRIM_Test.php +++ b/tests/Predis/Command/Redis/LTRIM_Test.php @@ -94,6 +94,26 @@ class LTRIM_Test extends PredisCommandTestCase $this->assertSame(['f', 'g', 'h', 'i', 'l'], $redis->lrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testTrimsListWithPositiveStartAndStopResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); + + $this->assertEquals('OK', $redis->ltrim('letters', 0, 2)); + $this->assertSame(['a', 'b', 'c'], $redis->lrange('letters', 0, -1)); + + $redis->flushdb(); + $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); + + $this->assertEquals('OK', $redis->ltrim('letters', 5, 9)); + $this->assertSame(['f', 'g', 'h', 'i', 'l'], $redis->lrange('letters', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/MGET_Test.php b/tests/Predis/Command/Redis/MGET_Test.php index e91afbe8..fa157192 100644 --- a/tests/Predis/Command/Redis/MGET_Test.php +++ b/tests/Predis/Command/Redis/MGET_Test.php @@ -107,6 +107,20 @@ class MGET_Test extends PredisCommandTestCase $this->assertSame(['bar', 'piyo'], $redis->mget('foo', 'hoge')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsArrayOfValuesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $redis->set('hoge', 'piyo'); + + $this->assertSame(['bar', 'piyo'], $redis->mget('foo', 'hoge')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/MIGRATE_Test.php b/tests/Predis/Command/Redis/MIGRATE_Test.php index fafe87b6..e0911189 100644 --- a/tests/Predis/Command/Redis/MIGRATE_Test.php +++ b/tests/Predis/Command/Redis/MIGRATE_Test.php @@ -118,6 +118,19 @@ class MIGRATE_Test extends PredisCommandTestCase $this->assertInstanceOf('Predis\Response\Status', $response); } + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsStatusNOKEYOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('NOKEY', $response = $redis->migrate('169.254.10.10', 16379, 'foo', 15, 1)); + $this->assertInstanceOf('Predis\Response\Status', $response); + } + /** * @group connected * @group ext-relay diff --git a/tests/Predis/Command/Redis/MONITOR_Test.php b/tests/Predis/Command/Redis/MONITOR_Test.php index 6a82705f..19f6130a 100644 --- a/tests/Predis/Command/Redis/MONITOR_Test.php +++ b/tests/Predis/Command/Redis/MONITOR_Test.php @@ -71,4 +71,23 @@ class MONITOR_Test extends PredisCommandTestCase $this->assertMatchesRegularExpression('/\d+.\d+(\s?\(db \d+\))? "MONITOR"/', $connection->read()); } } + + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsStatusResponseAndReadsEventsFromTheConnectionResp3(): void + { + $connection = $this->getResp3Client()->getConnection(); + $command = $this->getCommand(); + + $this->assertEquals('OK', $connection->executeCommand($command)); + + // NOTE: Starting with 2.6 Redis does not return the "MONITOR" message after + // +OK to the client that issued the MONITOR command. + if ($this->isRedisServerVersion('<=', '2.4.0')) { + $this->assertMatchesRegularExpression('/\d+.\d+(\s?\(db \d+\))? "MONITOR"/', $connection->read()); + } + } } diff --git a/tests/Predis/Command/Redis/MOVE_Test.php b/tests/Predis/Command/Redis/MOVE_Test.php index a61b40ed..c8da99be 100644 --- a/tests/Predis/Command/Redis/MOVE_Test.php +++ b/tests/Predis/Command/Redis/MOVE_Test.php @@ -98,6 +98,26 @@ class MOVE_Test extends PredisCommandTestCase $redis->del('foo'); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testMovesKeysToDifferentDatabasesResp3(): void + { + $db = REDIS_SERVER_DBNUM + 1; + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + + $this->assertSame(1, $redis->move('foo', $db)); + $this->assertSame(0, $redis->exists('foo')); + + $redis->select($db); + $this->assertSame(1, $redis->exists('foo')); + + $redis->del('foo'); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/MSETNX_Test.php b/tests/Predis/Command/Redis/MSETNX_Test.php index d3948b3b..0bf2cffd 100644 --- a/tests/Predis/Command/Redis/MSETNX_Test.php +++ b/tests/Predis/Command/Redis/MSETNX_Test.php @@ -83,6 +83,19 @@ class MSETNX_Test extends PredisCommandTestCase $this->assertSame('piyo', $redis->get('hoge')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesMultipleKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->msetnx('foo', 'bar', 'hoge', 'piyo')); + $this->assertSame('bar', $redis->get('foo')); + $this->assertSame('piyo', $redis->get('hoge')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/MSET_Test.php b/tests/Predis/Command/Redis/MSET_Test.php index d2942190..09d57cfd 100644 --- a/tests/Predis/Command/Redis/MSET_Test.php +++ b/tests/Predis/Command/Redis/MSET_Test.php @@ -100,4 +100,17 @@ class MSET_Test extends PredisCommandTestCase $this->assertSame('bar', $redis->get('foo')); $this->assertSame('piyo', $redis->get('hoge')); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesMultipleKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->mset('foo', 'bar', 'hoge', 'piyo')); + $this->assertSame('bar', $redis->get('foo')); + $this->assertSame('piyo', $redis->get('hoge')); + } } diff --git a/tests/Predis/Command/Redis/MULTI_Test.php b/tests/Predis/Command/Redis/MULTI_Test.php index e4d5b4e3..1a476069 100644 --- a/tests/Predis/Command/Redis/MULTI_Test.php +++ b/tests/Predis/Command/Redis/MULTI_Test.php @@ -66,6 +66,20 @@ class MULTI_Test extends PredisCommandTestCase $this->assertEquals('QUEUED', $redis->echo('tx2')); } + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testInitializesNewTransactionResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->multi()); + $this->assertEquals('QUEUED', $redis->echo('tx1')); + $this->assertEquals('QUEUED', $redis->echo('tx2')); + } + /** * @group connected * @group ext-relay diff --git a/tests/Predis/Command/Redis/OBJECT_Test.php b/tests/Predis/Command/Redis/OBJECT_Test.php index 7fbec0e6..a55774bf 100644 --- a/tests/Predis/Command/Redis/OBJECT_Test.php +++ b/tests/Predis/Command/Redis/OBJECT_Test.php @@ -68,6 +68,18 @@ class OBJECT_Test extends PredisCommandTestCase $this->assertIsInt($redis->object('REFCOUNT', 'foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testObjectRefcountResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $this->assertIsInt($redis->object('REFCOUNT', 'foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.3 @@ -80,6 +92,18 @@ class OBJECT_Test extends PredisCommandTestCase $this->assertIsInt($redis->object('IDLETIME', 'foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testObjectIdletimeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $this->assertIsInt($redis->object('IDLETIME', 'foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.3 @@ -92,6 +116,18 @@ class OBJECT_Test extends PredisCommandTestCase $this->assertMatchesRegularExpression('/[zip|quick]list/', $redis->object('ENCODING', 'list:metavars')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testObjectEncodingResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->lpush('list:metavars', 'foo', 'bar'); + $this->assertMatchesRegularExpression('/[zip|quick]list/', $redis->object('ENCODING', 'list:metavars')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.3 diff --git a/tests/Predis/Command/Redis/PERSIST_Test.php b/tests/Predis/Command/Redis/PERSIST_Test.php index c2dfaf71..7a204b81 100644 --- a/tests/Predis/Command/Redis/PERSIST_Test.php +++ b/tests/Predis/Command/Redis/PERSIST_Test.php @@ -93,6 +93,21 @@ class PERSIST_Test extends PredisCommandTestCase $this->assertSame(-1, $redis->ttl('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesExpireFromKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $redis->expire('foo', 10); + + $this->assertSame(1, $redis->persist('foo')); + $this->assertSame(-1, $redis->ttl('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/PEXPIREAT_Test.php b/tests/Predis/Command/Redis/PEXPIREAT_Test.php index 4e22201d..a5479a01 100644 --- a/tests/Predis/Command/Redis/PEXPIREAT_Test.php +++ b/tests/Predis/Command/Redis/PEXPIREAT_Test.php @@ -112,4 +112,18 @@ class PEXPIREAT_Test extends PredisCommandTestCase $this->assertSame(1, $redis->expireat('foo', time() - 100000)); $this->assertSame(0, $redis->exists('foo')); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testDeletesKeysOnPastUnixTimeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + + $this->assertSame(1, $redis->expireat('foo', time() - 100000)); + $this->assertSame(0, $redis->exists('foo')); + } } diff --git a/tests/Predis/Command/Redis/PEXPIRETIME_Test.php b/tests/Predis/Command/Redis/PEXPIRETIME_Test.php index 655a3225..1599a5bf 100644 --- a/tests/Predis/Command/Redis/PEXPIRETIME_Test.php +++ b/tests/Predis/Command/Redis/PEXPIRETIME_Test.php @@ -72,6 +72,25 @@ class PEXPIRETIME_Test extends PredisCommandTestCase $this->assertSame($expirationTime, $redis->pexpiretime('key')); $this->assertSame(-1, $redis->pexpiretime('key1')); - $this->assertSame(-2, $redis->pexpiretime('non-existing key')); + $this->assertSame(-2, $redis->pexpiretime('pexpire_non-existing-key')); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsCorrectExpirationTimeForGivenKeyResp3(): void + { + $redis = $this->getResp3Client(); + $expirationTime = time() * 1000 + 1000; + + $redis->set('key', 'value'); + $redis->set('key1', 'value'); + $redis->pexpireat('key', $expirationTime); + + $this->assertSame($expirationTime, $redis->pexpiretime('key')); + $this->assertSame(-1, $redis->pexpiretime('key1')); + $this->assertSame(-2, $redis->pexpiretime('pexpire_non-existing-key')); } } diff --git a/tests/Predis/Command/Redis/PEXPIRE_Test.php b/tests/Predis/Command/Redis/PEXPIRE_Test.php index 1b82b4c1..b7f0a8c3 100644 --- a/tests/Predis/Command/Redis/PEXPIRE_Test.php +++ b/tests/Predis/Command/Redis/PEXPIRE_Test.php @@ -89,6 +89,17 @@ class PEXPIRE_Test extends PredisCommandTestCase $this->assertSame(0, $redis->pexpire('foo', 20000)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsZeroOnNonExistingKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(0, $redis->pexpire('foo', 20000)); + } + /** * @medium * @group connected diff --git a/tests/Predis/Command/Redis/PING_Test.php b/tests/Predis/Command/Redis/PING_Test.php index 54b15fab..57674a4d 100644 --- a/tests/Predis/Command/Redis/PING_Test.php +++ b/tests/Predis/Command/Redis/PING_Test.php @@ -69,6 +69,20 @@ class PING_Test extends PredisCommandTestCase $this->assertEquals('PONG', $response); } + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testAlwaysReturnsStatusResponseResp3(): void + { + $redis = $this->getResp3Client(); + $response = $redis->ping(); + + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('PONG', $response); + } + /** * @group connected * @group ext-relay diff --git a/tests/Predis/Command/Redis/PSETEX_Test.php b/tests/Predis/Command/Redis/PSETEX_Test.php index 3efa025b..7932b943 100644 --- a/tests/Predis/Command/Redis/PSETEX_Test.php +++ b/tests/Predis/Command/Redis/PSETEX_Test.php @@ -88,6 +88,19 @@ class PSETEX_Test extends PredisCommandTestCase $this->assertSame(10, $redis->ttl('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyAndSetsTTLResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->psetex('foo', 10000, 'bar')); + $this->assertSame(1, $redis->exists('foo')); + $this->assertSame(10, $redis->ttl('foo')); + } + /** * @group connected * @group slow diff --git a/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php b/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php index 5ff1db4b..fdd82d3a 100644 --- a/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php +++ b/tests/Predis/Command/Redis/PSUBSCRIBE_Test.php @@ -13,6 +13,7 @@ namespace Predis\Command\Redis; use Predis\Command\PrefixableCommand; +use Predis\Consumer\Push\PushResponse; /** * @group commands @@ -106,6 +107,18 @@ class PSUBSCRIBE_Test extends PredisCommandTestCase $this->assertSame(['psubscribe', 'channel:*', 1], $redis->psubscribe('channel:*')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTheFirstPsubscribedChannelDetailsResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = new PushResponse(['psubscribe', 'channel:*', 1]); + + $this->assertEquals($expectedResponse, $redis->psubscribe('channel:*')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/PTTL_Test.php b/tests/Predis/Command/Redis/PTTL_Test.php index fbd0f304..e5b63085 100644 --- a/tests/Predis/Command/Redis/PTTL_Test.php +++ b/tests/Predis/Command/Redis/PTTL_Test.php @@ -91,6 +91,20 @@ class PTTL_Test extends PredisCommandTestCase $this->assertLessThanOrEqual(10000, $redis->pttl('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTTLResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $redis->expire('foo', 10); + + $this->assertLessThanOrEqual(10000, $redis->pttl('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/PUBLISH_Test.php b/tests/Predis/Command/Redis/PUBLISH_Test.php index 52b63370..02f65248 100644 --- a/tests/Predis/Command/Redis/PUBLISH_Test.php +++ b/tests/Predis/Command/Redis/PUBLISH_Test.php @@ -90,4 +90,20 @@ class PUBLISH_Test extends PredisCommandTestCase $this->assertSame(1, $redis2->publish('channel:foo', 'bar')); $this->assertSame(0, $redis2->publish('channel:hoge', 'piyo')); } + + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testPublishesMessagesToChannelResp3(): void + { + $redis1 = $this->getResp3Client(); + $redis2 = $this->getResp3Client(); + + $redis1->subscribe('channel:foo'); + + $this->assertSame(1, $redis2->publish('channel:foo', 'bar')); + $this->assertSame(0, $redis2->publish('channel:hoge', 'piyo')); + } } diff --git a/tests/Predis/Command/Redis/PUNSUBSCRIBE_Test.php b/tests/Predis/Command/Redis/PUNSUBSCRIBE_Test.php index 343a1d08..f6f0cdfb 100644 --- a/tests/Predis/Command/Redis/PUNSUBSCRIBE_Test.php +++ b/tests/Predis/Command/Redis/PUNSUBSCRIBE_Test.php @@ -13,6 +13,7 @@ namespace Predis\Command\Redis; use Predis\Command\PrefixableCommand; +use Predis\Consumer\Push\PushResponse; /** * @group commands @@ -107,6 +108,19 @@ class PUNSUBSCRIBE_Test extends PredisCommandTestCase $this->assertSame('echoed', $redis->echo('echoed')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testDoesNotSwitchToSubscribeModeResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = new PushResponse(['punsubscribe', 'channel:*', 0]); + + $this->assertEquals($expectedResponse, $redis->punsubscribe('channel:*')); + $this->assertSame('echoed', $redis->echo('echoed')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/QUIT_Test.php b/tests/Predis/Command/Redis/QUIT_Test.php index 94848412..4dc227e5 100644 --- a/tests/Predis/Command/Redis/QUIT_Test.php +++ b/tests/Predis/Command/Redis/QUIT_Test.php @@ -69,4 +69,19 @@ class QUIT_Test extends PredisCommandTestCase $this->assertInstanceOf('Predis\Response\Status', $response); $this->assertEquals('OK', $response); } + + /** + * @group connected + * @group relay-incompatible + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsStatusResponseWhenClosingConnectionResp3(): void + { + $redis = $this->getResp3Client(); + $command = $this->getCommand(); + $response = $redis->executeCommand($command); + + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('OK', $response); + } } diff --git a/tests/Predis/Command/Redis/RANDOMKEY_Test.php b/tests/Predis/Command/Redis/RANDOMKEY_Test.php index d074fa64..a514addb 100644 --- a/tests/Predis/Command/Redis/RANDOMKEY_Test.php +++ b/tests/Predis/Command/Redis/RANDOMKEY_Test.php @@ -74,6 +74,20 @@ class RANDOMKEY_Test extends PredisCommandTestCase $this->assertContains($redis->randomkey(), array_keys($keys)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsZeroOnNonExpiringKeysResp3(): void + { + $keys = ['key:1' => 1, 'key:2' => 2, 'key:3' => 3]; + + $redis = $this->getResp3Client(); + $redis->mset($keys); + + $this->assertContains($redis->randomkey(), array_keys($keys)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/RENAMENX_Test.php b/tests/Predis/Command/Redis/RENAMENX_Test.php index 6959f1fb..a08e0cc5 100644 --- a/tests/Predis/Command/Redis/RENAMENX_Test.php +++ b/tests/Predis/Command/Redis/RENAMENX_Test.php @@ -90,6 +90,21 @@ class RENAMENX_Test extends PredisCommandTestCase $this->assertSame(1, $redis->exists('foofoo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRenamesKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + + $this->assertSame(1, $redis->renamenx('foo', 'foofoo')); + $this->assertSame(0, $redis->exists('foo')); + $this->assertSame(1, $redis->exists('foofoo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/RENAME_Test.php b/tests/Predis/Command/Redis/RENAME_Test.php index 03518eee..a8251c48 100644 --- a/tests/Predis/Command/Redis/RENAME_Test.php +++ b/tests/Predis/Command/Redis/RENAME_Test.php @@ -89,6 +89,21 @@ class RENAME_Test extends PredisCommandTestCase $this->assertSame(1, $redis->exists('foofoo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRenamesKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + + $this->assertEquals('OK', $redis->rename('foo', 'foofoo')); + $this->assertSame(0, $redis->exists('foo')); + $this->assertSame(1, $redis->exists('foofoo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/RPOPLPUSH_Test.php b/tests/Predis/Command/Redis/RPOPLPUSH_Test.php index 84deac57..11a56bbf 100644 --- a/tests/Predis/Command/Redis/RPOPLPUSH_Test.php +++ b/tests/Predis/Command/Redis/RPOPLPUSH_Test.php @@ -92,6 +92,24 @@ class RPOPLPUSH_Test extends PredisCommandTestCase $this->assertSame(['a', 'b', 'c'], $redis->lrange('letters:destination', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementPoppedFromSourceAndPushesToDestinationResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters:source', 'a', 'b', 'c'); + + $this->assertSame('c', $redis->rpoplpush('letters:source', 'letters:destination')); + $this->assertSame('b', $redis->rpoplpush('letters:source', 'letters:destination')); + $this->assertSame('a', $redis->rpoplpush('letters:source', 'letters:destination')); + + $this->assertSame([], $redis->lrange('letters:source', 0, -1)); + $this->assertSame(['a', 'b', 'c'], $redis->lrange('letters:destination', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/RPOP_Test.php b/tests/Predis/Command/Redis/RPOP_Test.php index 1f2e7421..c5c8f832 100644 --- a/tests/Predis/Command/Redis/RPOP_Test.php +++ b/tests/Predis/Command/Redis/RPOP_Test.php @@ -89,6 +89,21 @@ class RPOP_Test extends PredisCommandTestCase $this->assertSame(['a', 'b'], $redis->lrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPopsTheLastElementFromListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('letters', 'a', 'b', 'c', 'd'); + + $this->assertSame('d', $redis->rpop('letters')); + $this->assertSame('c', $redis->rpop('letters')); + $this->assertSame(['a', 'b'], $redis->lrange('letters', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/RPUSHX_Test.php b/tests/Predis/Command/Redis/RPUSHX_Test.php index 8f59faee..b81200c9 100644 --- a/tests/Predis/Command/Redis/RPUSHX_Test.php +++ b/tests/Predis/Command/Redis/RPUSHX_Test.php @@ -89,6 +89,20 @@ class RPUSHX_Test extends PredisCommandTestCase $this->assertSame(['foo', 'hoge'], $redis->lrange('metavars', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPushesElementsToHeadOfExistingListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->rpush('metavars', 'foo'); + + $this->assertSame(2, $redis->rpushx('metavars', 'hoge')); + $this->assertSame(['foo', 'hoge'], $redis->lrange('metavars', 0, -1)); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/RPUSH_Test.php b/tests/Predis/Command/Redis/RPUSH_Test.php index accf14d7..8367e02c 100644 --- a/tests/Predis/Command/Redis/RPUSH_Test.php +++ b/tests/Predis/Command/Redis/RPUSH_Test.php @@ -102,6 +102,20 @@ class RPUSH_Test extends PredisCommandTestCase $this->assertSame(['foo', 'hoge'], $redis->lrange('metavars', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPushesElementsToHeadOfListResp3(): void + { + $redis = $this->getResp3Client(); + + // NOTE: List push operations return the list length since Redis commit 520b5a3 + $this->assertSame(1, $redis->rpush('metavars', 'foo')); + $this->assertSame(2, $redis->rpush('metavars', 'hoge')); + $this->assertSame(['foo', 'hoge'], $redis->lrange('metavars', 0, -1)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SADD_Test.php b/tests/Predis/Command/Redis/SADD_Test.php index 070dcd0b..5c87dbf5 100644 --- a/tests/Predis/Command/Redis/SADD_Test.php +++ b/tests/Predis/Command/Redis/SADD_Test.php @@ -101,6 +101,19 @@ class SADD_Test extends PredisCommandTestCase $this->assertSame(0, $redis->sadd('letters', 'b')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testAddsMembersToSetResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->sadd('letters', 'a')); + $this->assertSame(2, $redis->sadd('letters', 'b', 'c')); + $this->assertSame(0, $redis->sadd('letters', 'b')); + } + /** * @group connected * @requiresRedisVersion >= 2.4.0 diff --git a/tests/Predis/Command/Redis/SCAN_Test.php b/tests/Predis/Command/Redis/SCAN_Test.php index f5242817..a4a4612e 100644 --- a/tests/Predis/Command/Redis/SCAN_Test.php +++ b/tests/Predis/Command/Redis/SCAN_Test.php @@ -105,6 +105,22 @@ class SCAN_Test extends PredisCommandTestCase $this->assertSameValues(array_keys($kvs), $response[1]); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testScanWithoutMatchResp3(): void + { + $kvs = ['key:one' => 'one', 'key:two' => 'two', 'key:three' => 'three', 'key:four' => 'four']; + + $redis = $this->getResp3Client(); + $redis->mset($kvs); + + $response = $redis->scan(0); + + $this->assertSameValues(array_keys($kvs), $response[1]); + } + /** * @group connected * @requiresRedisVersion >= 2.8.0 diff --git a/tests/Predis/Command/Redis/SCARD_Test.php b/tests/Predis/Command/Redis/SCARD_Test.php index 8b6dc55b..4f831dcd 100644 --- a/tests/Predis/Command/Redis/SCARD_Test.php +++ b/tests/Predis/Command/Redis/SCARD_Test.php @@ -87,6 +87,19 @@ class SCARD_Test extends PredisCommandTestCase $this->assertSame(4, $redis->scard('letters')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsNumberOfMembersResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters', 'a', 'b', 'c', 'd'); + + $this->assertSame(4, $redis->scard('letters')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SCRIPT_Test.php b/tests/Predis/Command/Redis/SCRIPT_Test.php index ee92d6e6..6509ea64 100644 --- a/tests/Predis/Command/Redis/SCRIPT_Test.php +++ b/tests/Predis/Command/Redis/SCRIPT_Test.php @@ -70,6 +70,20 @@ class SCRIPT_Test extends PredisCommandTestCase $this->assertSame([1, 0], $redis->script('EXISTS', $sha1, 'ffffffffffffffffffffffffffffffffffffffff')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testExistsReturnsAnArrayOfValuesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->eval($lua = 'return true', 0); + $sha1 = sha1($lua); + + $this->assertSame([1, 0], $redis->script('EXISTS', $sha1, 'ffffffffffffffffffffffffffffffffffffffff')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 @@ -84,6 +98,20 @@ class SCRIPT_Test extends PredisCommandTestCase $this->assertSame($sha1, $redis->script('LOAD', $lua)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testLoadReturnsHashOfScriptsResp3(): void + { + $redis = $this->getResp3Client(); + + $lua = 'return true'; + $sha1 = sha1($lua); + + $this->assertSame($sha1, $redis->script('LOAD', $lua)); + } + /** * @group connected * @requiresRedisVersion >= 2.6.0 diff --git a/tests/Predis/Command/Redis/SDIFFSTORE_Test.php b/tests/Predis/Command/Redis/SDIFFSTORE_Test.php index d6c611eb..ace53f01 100644 --- a/tests/Predis/Command/Redis/SDIFFSTORE_Test.php +++ b/tests/Predis/Command/Redis/SDIFFSTORE_Test.php @@ -102,6 +102,20 @@ class SDIFFSTORE_Test extends PredisCommandTestCase $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->smembers('letters:destination')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testStoresMembersOfSetOnSingleSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:1st', 'a', 'b', 'c', 'd', 'e', 'f', 'g'); + + $this->assertSame(7, $redis->sdiffstore('letters:destination', 'letters:1st')); + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->smembers('letters:destination')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SDIFF_Test.php b/tests/Predis/Command/Redis/SDIFF_Test.php index 1a9a9f4b..dd4c819b 100644 --- a/tests/Predis/Command/Redis/SDIFF_Test.php +++ b/tests/Predis/Command/Redis/SDIFF_Test.php @@ -107,6 +107,20 @@ class SDIFF_Test extends PredisCommandTestCase $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sdiff('letters:1st', 'letters:2nd')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsMembersOnSingleKeyOrNonExistingSetForDifferenceResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:1st', 'a', 'b', 'c', 'd', 'e', 'f', 'g'); + + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sdiff('letters:1st')); + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sdiff('letters:1st', 'letters:2nd')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SETBIT_Test.php b/tests/Predis/Command/Redis/SETBIT_Test.php index 6ba9589b..477a223d 100644 --- a/tests/Predis/Command/Redis/SETBIT_Test.php +++ b/tests/Predis/Command/Redis/SETBIT_Test.php @@ -92,6 +92,21 @@ class SETBIT_Test extends PredisCommandTestCase $this->assertEquals("\x00\x00\00\x01", $redis->get('key:binary')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCanSetBitsOfStringsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('key:binary', "\x80\x00\00\x01"); + + $this->assertEquals(1, $redis->setbit('key:binary', 0, 0)); + $this->assertEquals(0, $redis->setbit('key:binary', 0, 0)); + $this->assertEquals("\x00\x00\00\x01", $redis->get('key:binary')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/SETEX_Test.php b/tests/Predis/Command/Redis/SETEX_Test.php index e14b4399..2d37ebfc 100644 --- a/tests/Predis/Command/Redis/SETEX_Test.php +++ b/tests/Predis/Command/Redis/SETEX_Test.php @@ -88,6 +88,19 @@ class SETEX_Test extends PredisCommandTestCase $this->assertSame(10, $redis->ttl('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyAndSetsTTLResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->setex('foo', 10, 'bar')); + $this->assertSame(1, $redis->exists('foo')); + $this->assertSame(10, $redis->ttl('foo')); + } + /** * @medium * @group connected diff --git a/tests/Predis/Command/Redis/SETNX_Test.php b/tests/Predis/Command/Redis/SETNX_Test.php index 2b5475cb..7df86485 100644 --- a/tests/Predis/Command/Redis/SETNX_Test.php +++ b/tests/Predis/Command/Redis/SETNX_Test.php @@ -87,4 +87,17 @@ class SETNX_Test extends PredisCommandTestCase $this->assertSame(0, $redis->setnx('foo', 'barbar')); $this->assertEquals('bar', $redis->get('foo')); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testSetStringValueResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->setnx('foo', 'bar')); + $this->assertSame(0, $redis->setnx('foo', 'barbar')); + $this->assertEquals('bar', $redis->get('foo')); + } } diff --git a/tests/Predis/Command/Redis/SETRANGE_Test.php b/tests/Predis/Command/Redis/SETRANGE_Test.php index 19b69702..452d5b5d 100644 --- a/tests/Predis/Command/Redis/SETRANGE_Test.php +++ b/tests/Predis/Command/Redis/SETRANGE_Test.php @@ -90,6 +90,21 @@ class SETRANGE_Test extends PredisCommandTestCase $this->assertSame("\x00\x00\x00\x00piyo", $redis->get('hoge')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testCreatesNewKeyOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(3, $redis->setrange('foo', 0, 'bar')); + $this->assertSame('bar', $redis->get('foo')); + + $this->assertSame(8, $redis->setrange('hoge', 4, 'piyo')); + $this->assertSame("\x00\x00\x00\x00piyo", $redis->get('hoge')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/SET_Test.php b/tests/Predis/Command/Redis/SET_Test.php index 8cc9dfe8..f82da5a4 100644 --- a/tests/Predis/Command/Redis/SET_Test.php +++ b/tests/Predis/Command/Redis/SET_Test.php @@ -101,6 +101,19 @@ class SET_Test extends PredisCommandTestCase $this->assertSame('bar', $redis->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testSetStringValueResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->set('foo', 'bar')); + $this->assertSame(1, $redis->exists('foo')); + $this->assertSame('bar', $redis->get('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.6.12 diff --git a/tests/Predis/Command/Redis/SINTERCARD_Test.php b/tests/Predis/Command/Redis/SINTERCARD_Test.php index c9518610..f31a650b 100644 --- a/tests/Predis/Command/Redis/SINTERCARD_Test.php +++ b/tests/Predis/Command/Redis/SINTERCARD_Test.php @@ -83,6 +83,21 @@ class SINTERCARD_Test extends PredisCommandTestCase $this->assertSame($expectedCardinality, $redis->sintercard($keys, $limit)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsCorrectCardinalityOfGivenSetIntersectionResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('key1', 'member1', 'member2', 'member3'); + $redis->sadd('key2', 'member1', 'member2', 'member3'); + + $this->assertSame(3, $redis->sintercard(['key1', 'key2'])); + } + /** * @group connected * @dataProvider unexpectedValuesProvider diff --git a/tests/Predis/Command/Redis/SINTERSTORE_Test.php b/tests/Predis/Command/Redis/SINTERSTORE_Test.php index ae775848..82474017 100644 --- a/tests/Predis/Command/Redis/SINTERSTORE_Test.php +++ b/tests/Predis/Command/Redis/SINTERSTORE_Test.php @@ -102,6 +102,20 @@ class SINTERSTORE_Test extends PredisCommandTestCase $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->smembers('letters:destination')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testStoresMembersOfSetOnSingleKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:1st', 'a', 'b', 'c', 'd', 'e', 'f', 'g'); + + $this->assertSame(7, $redis->sinterstore('letters:destination', 'letters:1st')); + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->smembers('letters:destination')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SINTER_Test.php b/tests/Predis/Command/Redis/SINTER_Test.php index a5feceec..757f2bff 100644 --- a/tests/Predis/Command/Redis/SINTER_Test.php +++ b/tests/Predis/Command/Redis/SINTER_Test.php @@ -106,6 +106,19 @@ class SINTER_Test extends PredisCommandTestCase $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sinter('letters:1st')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsMembersOfSetOnSingleKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:1st', 'a', 'b', 'c', 'd', 'e', 'f', 'g'); + + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sinter('letters:1st')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SISMEMBER_Test.php b/tests/Predis/Command/Redis/SISMEMBER_Test.php index 51fcc9a8..9bbbc397 100644 --- a/tests/Predis/Command/Redis/SISMEMBER_Test.php +++ b/tests/Predis/Command/Redis/SISMEMBER_Test.php @@ -91,6 +91,20 @@ class SISMEMBER_Test extends PredisCommandTestCase $this->assertSame(0, $redis->sismember('letters', 'z')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsMemberExistenceInSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters', 'a', 'b', 'c'); + + $this->assertSame(1, $redis->sismember('letters', 'a')); + $this->assertSame(0, $redis->sismember('letters', 'z')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SLOWLOG_Test.php b/tests/Predis/Command/Redis/SLOWLOG_Test.php index dce2dc44..c43b0948 100644 --- a/tests/Predis/Command/Redis/SLOWLOG_Test.php +++ b/tests/Predis/Command/Redis/SLOWLOG_Test.php @@ -111,6 +111,32 @@ class SLOWLOG_Test extends PredisCommandTestCase $redis->config('set', 'slowlog-log-slower-than', $threshold); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsAnArrayOfLoggedCommandsResp3(): void + { + $redis = $this->getResp3Client(); + + $config = $redis->config('get', 'slowlog-log-slower-than'); + $threshold = array_pop($config); + + $redis->config('set', 'slowlog-log-slower-than', 0); + $redis->set('foo', 'bar'); + + $this->assertIsArray($slowlog = $redis->slowlog('GET')); + $this->assertGreaterThan(0, count($slowlog)); + + $this->assertIsArray($slowlog[0]); + $this->assertGreaterThan(0, $slowlog[0]['id']); + $this->assertGreaterThan(0, $slowlog[0]['timestamp']); + $this->assertGreaterThanOrEqual(0, $slowlog[0]['duration']); + $this->assertIsArray($slowlog[0]['command']); + + $redis->config('set', 'slowlog-log-slower-than', $threshold); + } + /** * @group connected * @requiresRedisVersion >= 2.2.12 diff --git a/tests/Predis/Command/Redis/SMEMBERS_Test.php b/tests/Predis/Command/Redis/SMEMBERS_Test.php index 294d7353..7df4ef74 100644 --- a/tests/Predis/Command/Redis/SMEMBERS_Test.php +++ b/tests/Predis/Command/Redis/SMEMBERS_Test.php @@ -93,6 +93,20 @@ class SMEMBERS_Test extends PredisCommandTestCase $this->assertSame([], $redis->smembers('digits')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsEmptyArrayOnNonExistingSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters', 'a', 'b', 'c', 'd', 'e'); + + $this->assertSameValues(['a', 'b', 'c', 'd', 'e'], $redis->smembers('letters')); + $this->assertSame([], $redis->smembers('digits')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SMISMEMBER_Test.php b/tests/Predis/Command/Redis/SMISMEMBER_Test.php index 0bb8d2f3..a5bfba29 100644 --- a/tests/Predis/Command/Redis/SMISMEMBER_Test.php +++ b/tests/Predis/Command/Redis/SMISMEMBER_Test.php @@ -83,6 +83,20 @@ class SMISMEMBER_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->smismember($key, ...$members)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsCorrectResponseIfMemberBelongsToSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('key', 'member1'); + + $this->assertSame([1], $redis->smismember('key', 'member1')); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Command/Redis/SMOVE_Test.php b/tests/Predis/Command/Redis/SMOVE_Test.php index 3c8fe4c3..c2d4dd39 100644 --- a/tests/Predis/Command/Redis/SMOVE_Test.php +++ b/tests/Predis/Command/Redis/SMOVE_Test.php @@ -94,6 +94,23 @@ class SMOVE_Test extends PredisCommandTestCase $this->assertSameValues(['b'], $redis->smembers('letters:destination')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsMemberExistenceInSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:source', 'a', 'b', 'c'); + + $this->assertSame(1, $redis->smove('letters:source', 'letters:destination', 'b')); + $this->assertSame(0, $redis->smove('letters:source', 'letters:destination', 'z')); + + $this->assertSameValues(['a', 'c'], $redis->smembers('letters:source')); + $this->assertSameValues(['b'], $redis->smembers('letters:destination')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SORT_RO_Test.php b/tests/Predis/Command/Redis/SORT_RO_Test.php index dc15d347..ef29840b 100644 --- a/tests/Predis/Command/Redis/SORT_RO_Test.php +++ b/tests/Predis/Command/Redis/SORT_RO_Test.php @@ -78,6 +78,20 @@ class SORT_RO_Test extends PredisCommandTestCase $this->assertSame($expectedSortedResponse, $redis->sort_ro(...$sortArguments)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testSortItemsWithinGivenListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->lpush('key', 2, 1); + + $this->assertSame(['1', '2'], $redis->sort_ro('key')); + } + /** * @group connected * @dataProvider listsProvider diff --git a/tests/Predis/Command/Redis/SORT_Test.php b/tests/Predis/Command/Redis/SORT_Test.php index c9c9730b..fe8e5406 100644 --- a/tests/Predis/Command/Redis/SORT_Test.php +++ b/tests/Predis/Command/Redis/SORT_Test.php @@ -133,6 +133,18 @@ class SORT_Test extends PredisCommandTestCase $this->assertEquals([1, 2, 3, 10, 30, 100], $redis->sort('list:unordered')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testBasicSortResp3(): void + { + $redis = $this->getResp3Client(); + $redis->lpush('list:unordered', $unordered = [2, 100, 3, 1, 30, 10]); + + $this->assertEquals([1, 2, 3, 10, 30, 100], $redis->sort('list:unordered')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SPOP_Test.php b/tests/Predis/Command/Redis/SPOP_Test.php index 9071e93c..ae95ea6d 100644 --- a/tests/Predis/Command/Redis/SPOP_Test.php +++ b/tests/Predis/Command/Redis/SPOP_Test.php @@ -90,6 +90,22 @@ class SPOP_Test extends PredisCommandTestCase $this->assertNull($redis->spop('letters')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testPopsRandomMemberFromSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters', 'a', 'b'); + + $this->assertContains($redis->spop('letters'), ['a', 'b']); + $this->assertContains($redis->spop('letters'), ['a', 'b']); + + $this->assertNull($redis->spop('letters')); + } + /** * @group connected * @requiresRedisVersion >= 3.2.0 diff --git a/tests/Predis/Command/Redis/SRANDMEMBER_Test.php b/tests/Predis/Command/Redis/SRANDMEMBER_Test.php index 9cb8ec62..e0473cf7 100644 --- a/tests/Predis/Command/Redis/SRANDMEMBER_Test.php +++ b/tests/Predis/Command/Redis/SRANDMEMBER_Test.php @@ -90,6 +90,22 @@ class SRANDMEMBER_Test extends PredisCommandTestCase $this->assertSame(2, $redis->scard('letters')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsRandomMemberFromSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters', 'a', 'b'); + + $this->assertContains($redis->srandmember('letters'), ['a', 'b']); + $this->assertContains($redis->srandmember('letters'), ['a', 'b']); + + $this->assertSame(2, $redis->scard('letters')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SREM_Test.php b/tests/Predis/Command/Redis/SREM_Test.php index ebbf5983..5a602074 100644 --- a/tests/Predis/Command/Redis/SREM_Test.php +++ b/tests/Predis/Command/Redis/SREM_Test.php @@ -105,6 +105,23 @@ class SREM_Test extends PredisCommandTestCase $this->assertSame(0, $redis->srem('digits', 1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesMembersFromSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters', 'a', 'b', 'c', 'd'); + + $this->assertSame(1, $redis->srem('letters', 'b')); + $this->assertSame(1, $redis->srem('letters', 'd', 'z')); + $this->assertSameValues(['a', 'c'], $redis->smembers('letters')); + + $this->assertSame(0, $redis->srem('digits', 1)); + } + /** * @group connected * @requiresRedisVersion >= 2.4.0 diff --git a/tests/Predis/Command/Redis/SSCAN_Test.php b/tests/Predis/Command/Redis/SSCAN_Test.php index fcec6e80..6466069a 100644 --- a/tests/Predis/Command/Redis/SSCAN_Test.php +++ b/tests/Predis/Command/Redis/SSCAN_Test.php @@ -123,6 +123,21 @@ class SSCAN_Test extends PredisCommandTestCase $this->assertSameValues($members, $response[1]); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testScanWithoutMatchResp3(): void + { + $redis = $this->getResp3Client(); + $redis->sadd('key', $members = ['member:one', 'member:two', 'member:three', 'member:four']); + + $response = $redis->sscan('key', 0); + + $this->assertSame('0', $response[0]); + $this->assertSameValues($members, $response[1]); + } + /** * @group connected * @requiresRedisVersion >= 2.8.0 diff --git a/tests/Predis/Command/Redis/STRLEN_Test.php b/tests/Predis/Command/Redis/STRLEN_Test.php index df3f0838..981e07cd 100644 --- a/tests/Predis/Command/Redis/STRLEN_Test.php +++ b/tests/Predis/Command/Redis/STRLEN_Test.php @@ -90,6 +90,21 @@ class STRLEN_Test extends PredisCommandTestCase $this->assertSame(6, $redis->strlen('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTheLengthOfStringResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $this->assertSame(3, $redis->strlen('foo')); + + $redis->append('foo', 'bar'); + $this->assertSame(6, $redis->strlen('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/SUBSCRIBE_Test.php b/tests/Predis/Command/Redis/SUBSCRIBE_Test.php index 19fa688e..3a43a847 100644 --- a/tests/Predis/Command/Redis/SUBSCRIBE_Test.php +++ b/tests/Predis/Command/Redis/SUBSCRIBE_Test.php @@ -13,6 +13,7 @@ namespace Predis\Command\Redis; use Predis\Command\PrefixableCommand; +use Predis\Consumer\Push\PushResponse; /** * @group commands @@ -106,6 +107,18 @@ class SUBSCRIBE_Test extends PredisCommandTestCase $this->assertSame(['subscribe', 'channel', 1], $redis->subscribe('channel')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTheFirstSubscribedChannelDetailsResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = new PushResponse(['subscribe', 'channel', 1]); + + $this->assertEquals($expectedResponse, $redis->subscribe('channel')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/SUNIONSTORE_Test.php b/tests/Predis/Command/Redis/SUNIONSTORE_Test.php index 0c6ace50..ee2ff7dd 100644 --- a/tests/Predis/Command/Redis/SUNIONSTORE_Test.php +++ b/tests/Predis/Command/Redis/SUNIONSTORE_Test.php @@ -102,6 +102,20 @@ class SUNIONSTORE_Test extends PredisCommandTestCase $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->smembers('letters:destination')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testStoresMembersOfSetOnSingleSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:1st', 'a', 'b', 'c', 'd', 'e', 'f', 'g'); + + $this->assertSame(7, $redis->sunionstore('letters:destination', 'letters:1st')); + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->smembers('letters:destination')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/SUNION_Test.php b/tests/Predis/Command/Redis/SUNION_Test.php index c1bf85c1..7904a048 100644 --- a/tests/Predis/Command/Redis/SUNION_Test.php +++ b/tests/Predis/Command/Redis/SUNION_Test.php @@ -107,6 +107,20 @@ class SUNION_Test extends PredisCommandTestCase $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sunion('letters:1st', 'letters:2nd')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsMembersOnSingleKeyOrNonExistingSetForUnionResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->sadd('letters:1st', 'a', 'b', 'c', 'd', 'e', 'f', 'g'); + + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sunion('letters:1st')); + $this->assertSameValues(['a', 'b', 'c', 'd', 'e', 'f', 'g'], $redis->sunion('letters:1st', 'letters:2nd')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/Search/FTAGGREGATE_Test.php b/tests/Predis/Command/Redis/Search/FTAGGREGATE_Test.php index 5518709e..9163c763 100644 --- a/tests/Predis/Command/Redis/Search/FTAGGREGATE_Test.php +++ b/tests/Predis/Command/Redis/Search/FTAGGREGATE_Test.php @@ -113,6 +113,57 @@ class FTAGGREGATE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testReturnsAggregatedSearchResultWithGivenModifiersResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [ + 2, + [ + 'country', 'Ukraine', 'birth', '1995', 'country_birth_Vlad_count', '2', + ], + [ + 'country', 'Israel', 'birth', '1994', 'country_birth_Vlad_count', '1', + ], + ]; + + $ftCreateArguments = (new CreateArguments())->prefix(['user:']); + $schema = [ + new TextField('name'), + new TextField('country'), + new NumericField('dob', '', AbstractField::SORTABLE), + ]; + + $this->assertEquals('OK', $redis->ftcreate('idx', $schema, $ftCreateArguments)); + $this->assertSame( + 3, + $redis->hset('user:0', 'name', 'Vlad', 'country', 'Ukraine', 'dob', 813801600) + ); + $this->assertSame( + 3, + $redis->hset('user:1', 'name', 'Vlad', 'country', 'Israel', 'dob', 782265600) + ); + $this->assertSame( + 3, + $redis->hset('user:2', 'name', 'Vlad', 'country', 'Ukraine', 'dob', 813801600) + ); + + $ftAggregateArguments = (new AggregateArguments()) + ->apply('year(@dob)', 'birth') + ->groupBy('@country', '@birth') + ->reduce('COUNT', true, 'country_birth_Vlad_count') + ->sortBy(0, '@birth', 'DESC'); + + $this->assertSame( + $expectedResponse, + $redis->ftaggregate('idx', '@name: "Vlad"', $ftAggregateArguments) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTALIASADD_Test.php b/tests/Predis/Command/Redis/Search/FTALIASADD_Test.php index fb659acf..8211afab 100644 --- a/tests/Predis/Command/Redis/Search/FTALIASADD_Test.php +++ b/tests/Predis/Command/Redis/Search/FTALIASADD_Test.php @@ -83,6 +83,28 @@ class FTALIASADD_Test extends PredisCommandTestCase $this->assertEquals('OK', $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testAddAliasToGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = new CreateArguments(); + $arguments->prefix(['prefix:']); + $arguments->language(); + + $schema = [new TextField('text_field')]; + + $createResponse = $redis->ftcreate('index', $schema, $arguments); + $this->assertEquals('OK', $createResponse); + + $actualResponse = $redis->ftaliasadd('alias', 'index'); + $this->assertEquals('OK', $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTALIASDEL_Test.php b/tests/Predis/Command/Redis/Search/FTALIASDEL_Test.php index c448c799..20bb1910 100644 --- a/tests/Predis/Command/Redis/Search/FTALIASDEL_Test.php +++ b/tests/Predis/Command/Redis/Search/FTALIASDEL_Test.php @@ -76,6 +76,22 @@ class FTALIASDEL_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->ftaliasdel('alias')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testRemovesAliasFromGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $schema = [new TextField('text_field')]; + + $this->assertEquals('OK', $redis->ftcreate('index', $schema)); + $this->assertEquals('OK', $redis->ftaliasadd('alias', 'index')); + $this->assertEquals('OK', $redis->ftaliasdel('alias')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTALIASUPDATE_Test.php b/tests/Predis/Command/Redis/Search/FTALIASUPDATE_Test.php index e21531bb..19e405d0 100644 --- a/tests/Predis/Command/Redis/Search/FTALIASUPDATE_Test.php +++ b/tests/Predis/Command/Redis/Search/FTALIASUPDATE_Test.php @@ -78,6 +78,24 @@ class FTALIASUPDATE_Test extends PredisCommandTestCase $this->assertEquals('OK', $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testUpdateAliasAddAliasToGivenIndexIfAliasNotExistsResp3(): void + { + $redis = $this->getResp3Client(); + + $schema = [new TextField('text_field')]; + + $createResponse = $redis->ftcreate('index', $schema); + $this->assertEquals('OK', $createResponse); + + $actualResponse = $redis->ftaliasupdate('alias', 'index'); + $this->assertEquals('OK', $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTALTER_Test.php b/tests/Predis/Command/Redis/Search/FTALTER_Test.php index 06e815e5..e90ee748 100644 --- a/tests/Predis/Command/Redis/Search/FTALTER_Test.php +++ b/tests/Predis/Command/Redis/Search/FTALTER_Test.php @@ -77,6 +77,24 @@ class FTALTER_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->ftalter('index', $schema)); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testAddsAttributeToExistingIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $schema = [new TextField('field_name')]; + + $this->assertEquals('OK', $redis->ftcreate('index', $schema)); + + $schema = [new TextField('new_field_name')]; + + $this->assertEquals('OK', $redis->ftalter('index', $schema)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTCONFIG_Test.php b/tests/Predis/Command/Redis/Search/FTCONFIG_Test.php index 8b75363e..3bf522a5 100644 --- a/tests/Predis/Command/Redis/Search/FTCONFIG_Test.php +++ b/tests/Predis/Command/Redis/Search/FTCONFIG_Test.php @@ -99,6 +99,18 @@ class FTCONFIG_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->ftconfig->set('TIMEOUT', 42)); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testSetGivenRediSearchConfigurationParameterResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->ftconfig->set('TIMEOUT', 42)); + } + /** * @group connected * @return void @@ -112,6 +124,19 @@ class FTCONFIG_Test extends PredisCommandTestCase $this->assertEmpty($redis->ftconfig->get('foobar')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testGetReturnsGivenRediSearchConfigurationParameterResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals([['MAXEXPANSIONS', '200']], $redis->ftconfig->get('MAXEXPANSIONS')); + $this->assertEmpty($redis->ftconfig->get('foobar')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTCREATE_Test.php b/tests/Predis/Command/Redis/Search/FTCREATE_Test.php index 746d3d7b..1bc2c201 100644 --- a/tests/Predis/Command/Redis/Search/FTCREATE_Test.php +++ b/tests/Predis/Command/Redis/Search/FTCREATE_Test.php @@ -85,6 +85,31 @@ class FTCREATE_Test extends PredisCommandTestCase $this->assertEquals('OK', $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testCreatesSearchIndexWithGivenArgumentsAndSchemaResp3(): void + { + $redis = $this->getResp3Client(); + + $schema = [ + new TextField('first', 'fst', true, true), + new TextField('last'), + new NumericField('age'), + ]; + + $arguments = new CreateArguments(); + $arguments->prefix(['prefix:', 'prefix1:']); + $arguments->filter('@age>16'); + $arguments->stopWords(['hello', 'world']); + + $actualResponse = $redis->ftcreate('index', $schema, $arguments); + + $this->assertEquals('OK', $actualResponse); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Search/FTCURSOR_Test.php b/tests/Predis/Command/Redis/Search/FTCURSOR_Test.php index a814eaac..29b203b5 100644 --- a/tests/Predis/Command/Redis/Search/FTCURSOR_Test.php +++ b/tests/Predis/Command/Redis/Search/FTCURSOR_Test.php @@ -134,6 +134,63 @@ class FTCURSOR_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testReadAggregatedResultsFromExistingCursorResp3(): void + { + $redis = $this->getResp3Client(); + + $expectedResponse = [ + [ + 'country', 'Ukraine', 'birth', '1995', 'country_birth_Vlad_count', '2', + ], + [ + 'country', 'Israel', 'birth', '1994', 'country_birth_Vlad_count', '1', + ], + ]; + + $ftCreateArguments = (new CreateArguments())->prefix(['user:']); + $schema = [ + new TextField('name'), + new TextField('country'), + new NumericField('dob', '', AbstractField::SORTABLE), + ]; + + $this->assertEquals('OK', $redis->ftcreate('idx', $schema, $ftCreateArguments)); + $this->assertSame( + 3, + $redis->hset('user:0', 'name', 'Vlad', 'country', 'Ukraine', 'dob', 813801600) + ); + $this->assertSame( + 3, + $redis->hset('user:1', 'name', 'Vlad', 'country', 'Israel', 'dob', 782265600) + ); + $this->assertSame( + 3, + $redis->hset('user:2', 'name', 'Vlad', 'country', 'Ukraine', 'dob', 813801600) + ); + + $ftAggregateArguments = (new AggregateArguments()) + ->apply('year(@dob)', 'birth') + ->groupBy('@country', '@birth') + ->reduce('COUNT', true, 'country_birth_Vlad_count') + ->sortBy(0, '@birth', 'DESC') + ->withCursor(1); + + [$response, $cursor] = $redis->ftaggregate('idx', '@name: "Vlad"', $ftAggregateArguments); + $actualResponse = []; + + while ($cursor) { + $actualResponse[] = $response[1]; + [$response, $cursor] = $redis->ftcursor->read('idx', $cursor); + } + + $this->assertSame($expectedResponse, $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTDICTADD_Test.php b/tests/Predis/Command/Redis/Search/FTDICTADD_Test.php index 577fda96..3cb92fc8 100644 --- a/tests/Predis/Command/Redis/Search/FTDICTADD_Test.php +++ b/tests/Predis/Command/Redis/Search/FTDICTADD_Test.php @@ -71,4 +71,18 @@ class FTDICTADD_Test extends PredisCommandTestCase $this->assertSame(2, $actualResponse); } + + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testAddTermsIntoGivenDictionaryResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->ftdictadd('dict', 'foo', 'bar'); + + $this->assertSame(2, $actualResponse); + } } diff --git a/tests/Predis/Command/Redis/Search/FTDICTDEL_Test.php b/tests/Predis/Command/Redis/Search/FTDICTDEL_Test.php index 566add53..92bc48ad 100644 --- a/tests/Predis/Command/Redis/Search/FTDICTDEL_Test.php +++ b/tests/Predis/Command/Redis/Search/FTDICTDEL_Test.php @@ -79,6 +79,20 @@ class FTDICTDEL_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->ftdictdel(...$deleteArguments)); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testRemovesTermsFromGivenDictionaryResp3(): void + { + $redis = $this->getClient(); + + $redis->ftdictadd('dict', 'foo', 'bar'); + + $this->assertSame(1, $redis->ftdictdel('dict', 'foo')); + } + public function dictionariesProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Search/FTDICTDUMP_Test.php b/tests/Predis/Command/Redis/Search/FTDICTDUMP_Test.php index 7c260dc7..f25b9846 100644 --- a/tests/Predis/Command/Redis/Search/FTDICTDUMP_Test.php +++ b/tests/Predis/Command/Redis/Search/FTDICTDUMP_Test.php @@ -73,6 +73,20 @@ class FTDICTDUMP_Test extends PredisCommandTestCase $this->assertSame(['bar', 'foo'], $redis->ftdictdump('dict')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testDumpTermsFromGivenDictionaryResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->ftdictadd('dict', 'foo', 'bar'); + + $this->assertSame(['bar', 'foo'], $redis->ftdictdump('dict')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTDROPINDEX_Test.php b/tests/Predis/Command/Redis/Search/FTDROPINDEX_Test.php index d026db7a..142bf670 100644 --- a/tests/Predis/Command/Redis/Search/FTDROPINDEX_Test.php +++ b/tests/Predis/Command/Redis/Search/FTDROPINDEX_Test.php @@ -74,6 +74,21 @@ class FTDROPINDEX_Test extends PredisCommandTestCase $this->assertEquals('OK', $redis->ftdropindex('index')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testDropRemovesGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $schema = [new TextField('text_field')]; + + $this->assertEquals('OK', $redis->ftcreate('index', $schema)); + $this->assertEquals('OK', $redis->ftdropindex('index')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTEXPLAIN_Test.php b/tests/Predis/Command/Redis/Search/FTEXPLAIN_Test.php index 8d6dcead..5a39e0bd 100644 --- a/tests/Predis/Command/Redis/Search/FTEXPLAIN_Test.php +++ b/tests/Predis/Command/Redis/Search/FTEXPLAIN_Test.php @@ -97,6 +97,55 @@ INTERSECT { } } +EOT; + + $schema = [new TextField('text_field')]; + + $this->assertEquals('OK', $redis->ftcreate('index', $schema)); + $this->assertEquals( + $expectedResponse, + $redis->ftexplain('index', '(foo bar)|(hello world) @date:[100 200]|@date:[500 +inf]') + ); + } + + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testExplainReturnsExecutionPlanForGivenQueryResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = <<assertEquals('index', $actualResponse[1]); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testInfoReturnsInformationAboutGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = new CreateArguments(); + $arguments->prefix(['prefix:']); + $arguments->language(); + + $schema = [new TextField('text_field')]; + + $createResponse = $redis->ftcreate('index', $schema, $arguments); + $this->assertEquals('OK', $createResponse); + + $actualResponse = $redis->ftinfo('index'); + $this->assertEquals('index', $actualResponse[1]); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTPROFILE_Test.php b/tests/Predis/Command/Redis/Search/FTPROFILE_Test.php index 78c83c69..d0f96abd 100644 --- a/tests/Predis/Command/Redis/Search/FTPROFILE_Test.php +++ b/tests/Predis/Command/Redis/Search/FTPROFILE_Test.php @@ -77,6 +77,19 @@ class FTPROFILE_Test extends PredisCommandTestCase $this->assertNotEmpty($redis->ftprofile(...$profileArguments)); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testProfileReturnsPerformanceInformationAboutGivenQueryResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('OK', $redis->ftcreate('index', [new TextField('text_field')])); + $this->assertNotEmpty($redis->ftprofile('index', (new ProfileArguments())->aggregate()->query('hello world'))); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php b/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php index dfca91d5..8b5f6c4a 100644 --- a/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php @@ -123,6 +123,37 @@ class FTSEARCH_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testSearchValuesByHashIndexResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [1, 'doc:1', ['should_return', 'value1']]; + + $hashResponse = $redis->hmset('doc:1', 'field1', 'value1', 'field2', 'value2'); + $this->assertEquals('OK', $hashResponse); + + $ftCreateArguments = new CreateArguments(); + $ftCreateArguments->prefix(['doc:']); + + $schema = [ + new TextField('field1', 'should_return'), + new TextField('field2', 'should_not_return'), + ]; + + $ftCreateResponse = $redis->ftcreate('idx_hash', $schema, $ftCreateArguments); + $this->assertEquals('OK', $ftCreateResponse); + + $ftSearchArguments = new SearchArguments(); + $ftSearchArguments->addReturn(1, 'should_return'); + + $actualResponse = $redis->ftsearch('idx_hash', '*', $ftSearchArguments); + $this->assertSame($expectedResponse, $actualResponse); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Search/FTSPELLCHECK_Test.php b/tests/Predis/Command/Redis/Search/FTSPELLCHECK_Test.php index 16ee1f70..846fbb6f 100644 --- a/tests/Predis/Command/Redis/Search/FTSPELLCHECK_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSPELLCHECK_Test.php @@ -86,6 +86,32 @@ class FTSPELLCHECK_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testSpellcheckReturnsPossibleSuggestionsToGivenMisspelledTermResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [['TERM', 'held', [[0.0, 'hello'], [0.0, 'help']]]]; + + $this->assertEquals('OK', $redis->ftcreate( + 'index', + [new TextField('text_field')] + )); + + $this->assertEquals(2, $redis->ftdictadd('dict', 'hello', 'help')); + + $actualResponse = $redis->ftspellcheck( + 'index', + 'held', + (new SpellcheckArguments())->distance(2)->terms('dict') + ); + + $this->assertSame($expectedResponse, $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTSUGADD_Test.php b/tests/Predis/Command/Redis/Search/FTSUGADD_Test.php index f858796c..844318ab 100644 --- a/tests/Predis/Command/Redis/Search/FTSUGADD_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSUGADD_Test.php @@ -69,6 +69,18 @@ class FTSUGADD_Test extends PredisCommandTestCase $this->assertSame(1, $redis->ftsugadd('key', 'string', 1)); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testAddSuggestionStringIntoAutoCompleteDictionaryResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->ftsugadd('key', 'string', 1)); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/Search/FTSUGDEL_Test.php b/tests/Predis/Command/Redis/Search/FTSUGDEL_Test.php index 3a52e420..5aac173a 100644 --- a/tests/Predis/Command/Redis/Search/FTSUGDEL_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSUGDEL_Test.php @@ -71,6 +71,19 @@ class FTSUGDEL_Test extends PredisCommandTestCase $this->assertSame(1, $redis->ftsugdel('key', 'string')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testRemovesSuggestionFromGivenSuggestionIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1, $redis->ftsugadd('key', 'string', 1)); + $this->assertSame(1, $redis->ftsugdel('key', 'string')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTSUGGET_Test.php b/tests/Predis/Command/Redis/Search/FTSUGGET_Test.php index 3239d53d..3ad3d784 100644 --- a/tests/Predis/Command/Redis/Search/FTSUGGET_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSUGGET_Test.php @@ -98,6 +98,23 @@ class FTSUGGET_Test extends PredisCommandTestCase $this->assertSame(['hell'], $actualResponse); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testGetReturnsLimitedResultsWithMaxModifierResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->ftsugadd('key', 'hello', 2); + $redis->ftsugadd('key', 'hell', 2); + + $actualResponse = $redis->ftsugget('key', 'hel', (new SugGetArguments())->max(1)); + + $this->assertSame(['hell'], $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTSUGLEN_Test.php b/tests/Predis/Command/Redis/Search/FTSUGLEN_Test.php index 214ed246..779c4440 100644 --- a/tests/Predis/Command/Redis/Search/FTSUGLEN_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSUGLEN_Test.php @@ -72,4 +72,19 @@ class FTSUGLEN_Test extends PredisCommandTestCase $this->assertSame(2, $redis->ftsuglen('key')); } + + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testReturnsLengthOfGivenSuggestionDictionaryResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->ftsugadd('key', 'foo', 1); + $redis->ftsugadd('key', 'bar', 1); + + $this->assertSame(2, $redis->ftsuglen('key')); + } } diff --git a/tests/Predis/Command/Redis/Search/FTSYNDUMP_Test.php b/tests/Predis/Command/Redis/Search/FTSYNDUMP_Test.php index 2821f65a..a079bc83 100644 --- a/tests/Predis/Command/Redis/Search/FTSYNDUMP_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSYNDUMP_Test.php @@ -83,6 +83,29 @@ class FTSYNDUMP_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->ftsyndump('index')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testDumpReturnsContentOfSynonymGroupFromGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = ['term1', ['synonym1'], 'term2', ['synonym1']]; + + $this->assertEquals( + 'OK', + $redis->ftcreate('index', [new TextField('text_field')]) + ); + + $this->assertEquals( + 'OK', + $redis->ftsynupdate('index', 'synonym1', null, 'term1', 'term2') + ); + + $this->assertSame($expectedResponse, $redis->ftsyndump('index')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTSYNUPDATE_Test.php b/tests/Predis/Command/Redis/Search/FTSYNUPDATE_Test.php index 21c5eb1b..b35b791f 100644 --- a/tests/Predis/Command/Redis/Search/FTSYNUPDATE_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSYNUPDATE_Test.php @@ -79,6 +79,26 @@ class FTSYNUPDATE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testCreatesSynonymGroupWithinGivenIndexResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals( + 'OK', + $redis->ftcreate('index', [new TextField('text')]) + ); + + $this->assertEquals( + 'OK', + $redis->ftsynupdate('index', 'synonym1', null, 'term1', 'term2') + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/Search/FTTAGVALS_Test.php b/tests/Predis/Command/Redis/Search/FTTAGVALS_Test.php index 80a7813a..1239721d 100644 --- a/tests/Predis/Command/Redis/Search/FTTAGVALS_Test.php +++ b/tests/Predis/Command/Redis/Search/FTTAGVALS_Test.php @@ -93,6 +93,38 @@ class FTTAGVALS_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->fttagvals('index', 'tag_field')); } + /** + * @group connected + * @return void + * @requiresRediSearchVersion >= 2.8.0 + */ + public function testReturnIndexedTagFieldDistinctValuesResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = ['hello', 'hey', 'world']; + + $this->assertEquals( + 'OK', + $redis->ftcreate( + 'index', + [new TagField('tag_field')], + (new CreateArguments())->prefix(['prefix:']) + ) + ); + + $this->assertSame( + 1, + $redis->hset('prefix:1', 'tag_field', 'Hello, World') + ); + + $this->assertSame( + 1, + $redis->hset('prefix:2', 'tag_field', 'Hey, World') + ); + + $this->assertSame($expectedResponse, $redis->fttagvals('index', 'tag_field')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTADD_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTADD_Test.php index fa76ee6a..2b75bbeb 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTADD_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTADD_Test.php @@ -77,6 +77,24 @@ class TDIGESTADD_Test extends PredisCommandTestCase $this->assertSame(3, $info['Observations']); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testAddObservationsIntoGivenTDigestSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('key'); + + $actualResponse = $redis->tdigestadd('key', 1, 2, 3); + $info = $redis->tdigestinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(3, $info['Observations']); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php index 4aadeb79..10efdb97 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTBYRANK_Test.php @@ -80,6 +80,27 @@ class TDIGESTBYRANK_Test extends PredisCommandTestCase $this->assertEquals(['nan', 'nan'], $redis->tdigestbyrank('empty_key', 0, 1)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsValuesEstimatedForGivenRanksResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [1.0, 2.0, 2.0, 3.0, 3.0, 3.0, INF]; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $actualResponse = $redis->tdigestbyrank('key', 0, 1, 2, 3, 4, 5, 6); + + $this->assertEquals($expectedResponse, $actualResponse); + $this->assertEquals([null, null], $redis->tdigestbyrank('empty_key', 0, 1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php index 7fc8a3a1..b5a1cbb0 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTBYREVRANK_Test.php @@ -80,6 +80,27 @@ class TDIGESTBYREVRANK_Test extends PredisCommandTestCase $this->assertEquals(['nan', 'nan'], $redis->tdigestbyrevrank('empty_key', 0, 1)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsValuesEstimatedForGivenReverseRanksResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [3.0, 3.0, 3.0, 2.0, 2.0, 1.0, INF]; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $actualResponse = $redis->tdigestbyrevrank('key', 0, 1, 2, 3, 4, 5, 6); + + $this->assertEquals($expectedResponse, $actualResponse); + $this->assertEquals([null, null], $redis->tdigestbyrevrank('empty_key', 0, 1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTCDF_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTCDF_Test.php index 2b23e6ae..6bd079c0 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTCDF_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTCDF_Test.php @@ -76,8 +76,29 @@ class TDIGESTCDF_Test extends PredisCommandTestCase $actualResponse = $redis->tdigestcdf('key', 0, 1, 2, 3, 4); - $this->assertEquals($expectedResponse, $actualResponse); - $this->assertEquals(['nan', 'nan'], $redis->tdigestcdf('empty_key', 0, 1)); + $this->assertSameWithPrecision($expectedResponse, $actualResponse, 5); + $this->assertSame(['nan', 'nan'], $redis->tdigestcdf('empty_key', 0, 1)); + } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsValuesEstimatedForGivenRanksResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [0.0, 0.083333333333333329, 0.33333333333333331, 0.75, 1.0]; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $actualResponse = $redis->tdigestcdf('key', 0, 1, 2, 3, 4); + + $this->assertSameWithPrecision($expectedResponse, $actualResponse, 5); + $this->assertSame([0.0, 0.0], $redis->tdigestcdf('empty_key', 0, 1)); } /** diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTCREATE_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTCREATE_Test.php index 39bcc23c..74de494e 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTCREATE_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTCREATE_Test.php @@ -80,6 +80,22 @@ class TDIGESTCREATE_Test extends PredisCommandTestCase $this->assertSame($expectedCompression, $info['Compression']); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testCreateTDigestSketchWithGivenConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->tdigestcreate('key'); + $info = $redis->tdigestinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(100, $info['Compression']); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php index 86072cc2..26a3c29f 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php @@ -100,6 +100,31 @@ class TDIGESTINFO_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->tdigestinfo('key')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testInfoReturnsInformationAboutGivenTDigestSketchResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [ + 'Compression' => 100, + 'Capacity' => 610, + 'Merged nodes' => 0, + 'Unmerged nodes' => 0, + 'Merged weight' => 0, + 'Unmerged weight' => 0, + 'Observations' => 0, + 'Total compressions' => 0, + 'Memory usage' => 9768, + ]; + + $redis->tdigestcreate('key'); + + $this->assertSame($expectedResponse, $redis->tdigestinfo('key')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTMAX_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTMAX_Test.php index 62b0a7a8..a1afe941 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTMAX_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTMAX_Test.php @@ -79,6 +79,26 @@ class TDIGESTMAX_Test extends PredisCommandTestCase $this->assertEquals('nan', $redis->tdigestmax('empty_key')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsMaxValueFromGivenSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 3, 2, 4, 5, 1); + + $actualResponse = $redis->tdigestmax('key'); + + $this->assertEquals('5', $actualResponse); + $this->assertEquals(0, $redis->tdigestmax('empty_key')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTMERGE_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTMERGE_Test.php index b4d73071..85ab8acd 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTMERGE_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTMERGE_Test.php @@ -116,6 +116,32 @@ class TDIGESTMERGE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testMergedSketchHaveCompressionEqualMaxValueAmongAllSourceSketchesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('source-key1'); + $redis->tdigestcreate('source-key2', 1000); + + $redis->tdigestadd('source-key1', 1, 2); + $redis->tdigestadd('source-key2', 3, 4); + + $actualResponse = $redis->tdigestmerge('destination-key', ['source-key1', 'source-key2']); + $info = $redis->tdigestinfo('destination-key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(1000, $info['Compression']); + $this->assertEquals( + [1.0, 2.0, 3.0, 4.0, INF], + $redis->tdigestbyrank('destination-key', 0, 1, 2, 3, 4) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTMIN_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTMIN_Test.php index c7062995..2127ed0b 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTMIN_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTMIN_Test.php @@ -79,6 +79,26 @@ class TDIGESTMIN_Test extends PredisCommandTestCase $this->assertEquals('nan', $redis->tdigestmin('empty_key')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsMinValueFromGivenSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 3, 2, 4, 5, 1); + + $actualResponse = $redis->tdigestmin('key'); + + $this->assertEquals('1', $actualResponse); + $this->assertEquals(0, $redis->tdigestmin('empty_key')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTQUANTILE_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTQUANTILE_Test.php index b43cc533..068b2e60 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTQUANTILE_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTQUANTILE_Test.php @@ -80,6 +80,27 @@ class TDIGESTQUANTILE_Test extends PredisCommandTestCase $this->assertEquals(['nan', 'nan'], $redis->tdigestquantile('empty_key', 0.0, 0.1)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsValuesBelowGivenQuantileResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('key', 1000); + + $addResponse = $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5); + $quantileResponse = $redis->tdigestquantile('key', 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0); + + $this->assertEquals('OK', $addResponse); + $this->assertEquals([1.0, 2.0, 3.0, 3.0, 4.0, 4.0, 4.0, 5.0, 5.0, 5.0, 5.0], $quantileResponse); + + $redis->tdigestcreate('empty_key'); + $this->assertEquals([null, null], $redis->tdigestquantile('empty_key', 0.0, 0.1)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTRANK_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTRANK_Test.php index b3e2502f..1cdafaf3 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTRANK_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTRANK_Test.php @@ -80,6 +80,27 @@ class TDIGESTRANK_Test extends PredisCommandTestCase $this->assertSame([-2, -2, -2], $redis->tdigestrank('empty_key', 1, 2, 3)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsRankOfGivenObservationValueResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [-1, 0, 1, 2, 3]; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 10, 20, 30); + + $actualResponse = $redis->tdigestrank('key', 0, 10, 20, 30, 40); + + $this->assertSame($expectedResponse, $actualResponse); + $this->assertSame([-2, -2, -2], $redis->tdigestrank('empty_key', 1, 2, 3)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTRESET_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTRESET_Test.php index bc3ebe25..99fa8edd 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTRESET_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTRESET_Test.php @@ -87,6 +87,34 @@ class TDIGESTRESET_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testResetExistingSketchResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('key', 500); + $redis->tdigestadd('key', 1, 2, 2, 3, 3, 3); + + $this->assertEquals( + ['1', '2', '2', '3', '3', '3'], + $redis->tdigestbyrank('key', 0, 1, 2, 3, 4, 5) + ); + + $actualResponse = $redis->tdigestreset('key'); + $info = $redis->tdigestinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSame(500, $info['Compression']); + $this->assertEquals( + [null, null, null, null, null, null], + $redis->tdigestbyrank('key', 0, 1, 2, 3, 4, 5) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTREVRANK_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTREVRANK_Test.php index 67b4799d..093b8e75 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTREVRANK_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTREVRANK_Test.php @@ -80,6 +80,27 @@ class TDIGESTREVRANK_Test extends PredisCommandTestCase $this->assertSame([-2, -2, -2], $redis->tdigestrank('empty_key', 1, 2, 3)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsReversedRanksOfGivenObservationsValueResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [3, 2, 1, 0, -1]; + + $redis->tdigestcreate('key'); + $redis->tdigestcreate('empty_key'); + + $redis->tdigestadd('key', 10, 20, 30); + + $actualResponse = $redis->tdigestrevrank('key', 0, 10, 20, 30, 40); + + $this->assertSame($expectedResponse, $actualResponse); + $this->assertSame([-2, -2, -2], $redis->tdigestrank('empty_key', 1, 2, 3)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTTRIMMED_MEAN_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTTRIMMED_MEAN_Test.php index 15490426..da7f56af 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTTRIMMED_MEAN_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTTRIMMED_MEAN_Test.php @@ -85,6 +85,23 @@ class TDIGESTTRIMMED_MEAN_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsMeanValueWithinGivenQuantilesRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->tdigestcreate('key'); + $redis->tdigestadd('key', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + + $actualResponse = $redis->tdigesttrimmed_mean('key', 0.1, 0.6); + + $this->assertEquals(4.0, $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TIME_Test.php b/tests/Predis/Command/Redis/TIME_Test.php index 8363224b..db2eea45 100644 --- a/tests/Predis/Command/Redis/TIME_Test.php +++ b/tests/Predis/Command/Redis/TIME_Test.php @@ -71,4 +71,17 @@ class TIME_Test extends PredisCommandTestCase $this->assertIsString($time[0]); $this->assertIsString($time[1]); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsServerTimeResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertIsArray($time = $redis->time()); + $this->assertIsString($time[0]); + $this->assertIsString($time[1]); + } } diff --git a/tests/Predis/Command/Redis/TOUCH_Test.php b/tests/Predis/Command/Redis/TOUCH_Test.php index 272869e1..8640099f 100644 --- a/tests/Predis/Command/Redis/TOUCH_Test.php +++ b/tests/Predis/Command/Redis/TOUCH_Test.php @@ -96,4 +96,24 @@ class TOUCH_Test extends PredisCommandTestCase $this->assertSame(1, $redis->touch('foo')); $this->assertSame(2, $redis->touch('foo', 'hoge')); } + + /** + * @requiresRedisVersion >= 6.0.0 + * + * @group connected + */ + public function testReturnsNumberOfDeletedKeysResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(0, $redis->touch('foo')); + + $redis->set('foo', 'bar'); + $this->assertSame(1, $redis->touch('foo')); + $this->assertSame(1, $redis->touch('foo', 'hoge')); + + $redis->set('hoge', 'piyo'); + $this->assertSame(1, $redis->touch('foo')); + $this->assertSame(2, $redis->touch('foo', 'hoge')); + } } diff --git a/tests/Predis/Command/Redis/TTL_Test.php b/tests/Predis/Command/Redis/TTL_Test.php index ee46224a..6981cca5 100644 --- a/tests/Predis/Command/Redis/TTL_Test.php +++ b/tests/Predis/Command/Redis/TTL_Test.php @@ -90,6 +90,20 @@ class TTL_Test extends PredisCommandTestCase $this->assertSame(10, $redis->ttl('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTTLResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->set('foo', 'bar'); + $redis->expire('foo', 10); + + $this->assertSame(10, $redis->ttl('foo')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/TYPE_Test.php b/tests/Predis/Command/Redis/TYPE_Test.php index 986c9b41..dacfdf3b 100644 --- a/tests/Predis/Command/Redis/TYPE_Test.php +++ b/tests/Predis/Command/Redis/TYPE_Test.php @@ -99,4 +99,30 @@ class TYPE_Test extends PredisCommandTestCase $redis->hset('type:hash', 'foo', 'bar'); $this->assertEquals('hash', $redis->type('type:hash')); } + + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsTypeOfKeyResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertEquals('none', $redis->type('type:keydoesnotexist')); + + $redis->set('type:string', 'foobar'); + $this->assertEquals('string', $redis->type('type:string')); + + $redis->lpush('type:list', 'foobar'); + $this->assertEquals('list', $redis->type('type:list')); + + $redis->sadd('type:set', 'foobar'); + $this->assertEquals('set', $redis->type('type:set')); + + $redis->zadd('type:zset', 0, 'foobar'); + $this->assertEquals('zset', $redis->type('type:zset')); + + $redis->hset('type:hash', 'foo', 'bar'); + $this->assertEquals('hash', $redis->type('type:hash')); + } } diff --git a/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php index a969e88e..113af083 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSADD_Test.php @@ -87,6 +87,34 @@ class TSADD_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testAddSampleIntoTimeSeriesWithGivenConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $createArguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $createArguments) + ); + + $addArguments = (new AddArguments()) + ->retentionMsecs(31536000000); + + $this->assertEquals( + 123123123123, + $redis->tsadd('temperature:2:32', 123123123123, 27, $addArguments) + ); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php index 01f6fd3e..8a699176 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSALTER_Test.php @@ -88,6 +88,34 @@ class TSALTER_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testAlterUpdatesExistingTimeSeriesConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $arguments) + ); + + $alterArguments = (new AlterArguments()) + ->retentionMsecs(10000000); + + $this->assertEquals( + 'OK', + $redis->tsalter('temperature:2:32', $alterArguments) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSCREATERULE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSCREATERULE_Test.php index 25a448f2..7110aca4 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSCREATERULE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSCREATERULE_Test.php @@ -78,6 +78,26 @@ class TSCREATERULE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testCreateCompactionRuleWithinGivenTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + $this->assertEquals('OK', $redis->tscreate('dailyAvgTemp:TLV', $arguments)); + $this->assertEquals( + 'OK', + $redis->tscreaterule('temp:TLV', 'dailyAvgTemp:TLV', 'twa', 86400000) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php index ef7c66ce..9be0e670 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSCREATE_Test.php @@ -79,6 +79,26 @@ class TSCREATE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testCreatesTimeSeriesWithGivenArgumentsResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $arguments) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php index 422ba42d..cda5ee67 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSDECRBY_Test.php @@ -94,6 +94,39 @@ class TSDECRBY_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testDecrByDecreasesValueAndTimestampOfExistingSampleResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $arguments) + ); + + $addArguments = (new AddArguments()) + ->retentionMsecs(31536000000); + + $this->assertEquals( + 123123123123, + $redis->tsadd('temperature:2:32', 123123123123, 27, $addArguments) + ); + + $this->assertEquals( + 123123123124, + $redis->tsdecrby('temperature:2:32', 1, (new DecrByArguments())->timestamp(123123123124)) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSDELETERULE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSDELETERULE_Test.php index ac581894..dbfd3be8 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSDELETERULE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSDELETERULE_Test.php @@ -84,6 +84,30 @@ class TSDELETERULE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testDeleteCompactionRuleFromGivenTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + $this->assertEquals('OK', $redis->tscreate('dailyAvgTemp:TLV', $arguments)); + $this->assertEquals( + 'OK', + $redis->tscreaterule('temp:TLV', 'dailyAvgTemp:TLV', 'twa', 86400000) + ); + $this->assertEquals( + 'OK', + $redis->tsdeleterule('temp:TLV', 'dailyAvgTemp:TLV') + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php index a9506eab..29f85f2b 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSDEL_Test.php @@ -103,6 +103,48 @@ class TSDEL_Test extends PredisCommandTestCase $this->assertEquals([123123123123, '27'], $redis->tsget('temperature:2:32')); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.6.0 + */ + public function testDelRemovesSamplesWithinGivenTimestampsRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $createArguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $createArguments) + ); + + $this->assertEquals( + 123123123123, + $redis->tsadd('temperature:2:32', 123123123123, 27) + ); + + $this->assertEquals( + 123123123124, + $redis->tsadd('temperature:2:32', 123123123124, 28) + ); + + $this->assertEquals( + 123123123125, + $redis->tsadd('temperature:2:32', 123123123125, 29) + ); + + $this->assertSame( + 2, + $redis->tsdel('temperature:2:32', 123123123124, 123123123125) + ); + + $this->assertEquals([123123123123, '27'], $redis->tsget('temperature:2:32')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php index 4ab298df..a1df3e41 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSGET_Test.php @@ -97,6 +97,43 @@ class TSGET_Test extends PredisCommandTestCase $this->assertEquals([123123123125, '29'], $redis->tsget('temperature:2:32')); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testGetSampleWithHighestTimestampFromGivenTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + + $createArguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $createArguments) + ); + + $this->assertEquals( + 123123123123, + $redis->tsadd('temperature:2:32', 123123123123, 27) + ); + + $this->assertEquals( + 123123123124, + $redis->tsadd('temperature:2:32', 123123123124, 28) + ); + + $this->assertEquals( + 123123123125, + $redis->tsadd('temperature:2:32', 123123123125, 29) + ); + + $this->assertEquals([123123123125, '29'], $redis->tsget('temperature:2:32')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php index 26273e82..18ea9e72 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSINCRBY_Test.php @@ -94,6 +94,39 @@ class TSINCRBY_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testIncrByIncreasesValueAndTimestampOfExistingSampleResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $arguments) + ); + + $addArguments = (new AddArguments()) + ->retentionMsecs(31536000000); + + $this->assertEquals( + 123123123123, + $redis->tsadd('temperature:2:32', 123123123123, 27, $addArguments) + ); + + $this->assertEquals( + 123123123124, + $redis->tsincrby('temperature:2:32', 28, (new IncrByArguments())->timestamp(123123123124)) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php index 20566d53..36ef7ff1 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSINFO_Test.php @@ -84,6 +84,31 @@ class TSINFO_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $redis->tsinfo('temperature:2:32')); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.10.0 + */ + public function testReturnsInformationAboutGivenTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = ['totalSamples' => 0, 'memoryUsage' => 4239, 'firstTimestamp' => 0, 'lastTimestamp' => 0, + 'retentionTime' => 60000, 'chunkCount' => 1, 'chunkSize' => 4096, 'chunkType' => 'compressed', + 'duplicatePolicy' => 'max', 'labels' => ['sensor_id' => '2', 'area_id' => '32'], 'sourceKey' => null, 'rules' => []]; + + $arguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $arguments) + ); + + $this->assertEquals($expectedResponse, $redis->tsinfo('temperature:2:32')); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php index 6f1a6ac5..fc6cc6dc 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSMADD_Test.php @@ -91,6 +91,36 @@ class TSMADD_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testAddSamplesIntoFewTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + + $createArguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $createArguments) + ); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:33', $createArguments) + ); + + $this->assertEquals( + [123123123123, 123123123124], + $redis->tsmadd('temperature:2:32', 123123123123, 27, 'temperature:2:33', 123123123124, 28) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php index 74d5b981..7bb71360 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSMGET_Test.php @@ -96,6 +96,43 @@ class TSMGET_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.10.0 + */ + public function testGetSampleFromMultipleTimeSeriesMatchingGivenPatternResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [ + 'temperature:2:32' => [['type' => 'temp'], [123123123123, 27]], + 'temperature:2:33' => [['type' => 'temp'], [123123123124, 27]], + ]; + + $createArguments = (new CreateArguments()) + ->retentionMsecs(60000) + ->duplicatePolicy(CommonArguments::POLICY_MAX) + ->labels('type', 'temp', 'sensor_id', 2, 'area_id', 32); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:32', $createArguments) + ); + + $this->assertEquals( + 'OK', + $redis->tscreate('temperature:2:33', $createArguments) + ); + + $redis->tsadd('temperature:2:32', 123123123123, 27); + $redis->tsadd('temperature:2:33', 123123123124, 27); + + $this->assertEquals( + $expectedResponse, + $redis->tsmget((new MGetArguments())->selectedLabels('type'), 'type=temp') + ); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/TimeSeries/TSMRANGE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSMRANGE_Test.php index cd7c126e..3daea34a 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSMRANGE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSMRANGE_Test.php @@ -107,6 +107,52 @@ class TSMRANGE_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $redis->tsmrange('-', '+', $mrangeArguments)); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.10.0 + */ + public function testQueryRangeAcrossMultipleTimeSeriesInForwardDirectionResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [ + 'type=stock' => [ + ['type' => 'stock'], + ['reducers' => ['max']], + ['sources' => ['stock:A', 'stock:B']], + [ + [1000, 120], + [1010, 110], + [1020, 120], + ], + ], + ]; + + $this->assertEquals( + 'OK', + $redis->tscreate('stock:A', (new CreateArguments())->labels('type', 'stock', 'name', 'A')) + ); + $this->assertEquals( + 'OK', + $redis->tscreate('stock:B', (new CreateArguments())->labels('type', 'stock', 'name', 'B')) + ); + $this->assertSame( + [1000, 1010, 1020], + $redis->tsmadd('stock:A', 1000, 100, 'stock:A', 1010, 110, 'stock:A', 1020, 120) + ); + $this->assertSame( + [1000, 1010, 1020], + $redis->tsmadd('stock:B', 1000, 120, 'stock:B', 1010, 110, 'stock:B', 1020, 100) + ); + + $mrangeArguments = (new MRangeArguments()) + ->withLabels() + ->filter('type=stock') + ->groupBy('type', 'max'); + + $this->assertEquals($expectedResponse, $redis->tsmrange('-', '+', $mrangeArguments)); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/TimeSeries/TSMREVRANGE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSMREVRANGE_Test.php index 8d5a9adb..e0831c3c 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSMREVRANGE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSMREVRANGE_Test.php @@ -107,6 +107,52 @@ class TSMREVRANGE_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $redis->tsmrevrange('-', '+', $mrangeArguments)); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.10.0 + */ + public function testQueryRangeAcrossMultipleTimeSeriesInReverseDirectionResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = [ + 'type=stock' => [ + ['type' => 'stock'], + ['reducers' => ['max']], + ['sources' => ['stock:A', 'stock:B']], + [ + [1020, 120], + [1010, 110], + [1000, 120], + ], + ], + ]; + + $this->assertEquals( + 'OK', + $redis->tscreate('stock:A', (new CreateArguments())->labels('type', 'stock', 'name', 'A')) + ); + $this->assertEquals( + 'OK', + $redis->tscreate('stock:B', (new CreateArguments())->labels('type', 'stock', 'name', 'B')) + ); + $this->assertSame( + [1000, 1010, 1020], + $redis->tsmadd('stock:A', 1000, 100, 'stock:A', 1010, 110, 'stock:A', 1020, 120) + ); + $this->assertSame( + [1000, 1010, 1020], + $redis->tsmadd('stock:B', 1000, 120, 'stock:B', 1010, 110, 'stock:B', 1020, 100) + ); + + $mrangeArguments = (new MRangeArguments()) + ->withLabels() + ->filter('type=stock') + ->groupBy('type', 'max'); + + $this->assertEquals($expectedResponse, $redis->tsmrevrange('-', '+', $mrangeArguments)); + } + public function argumentsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/TimeSeries/TSQUERYINDEX_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSQUERYINDEX_Test.php index 0630300c..ffbb08c8 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSQUERYINDEX_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSQUERYINDEX_Test.php @@ -74,6 +74,28 @@ class TSQUERYINDEX_Test extends PredisCommandTestCase $this->assertSame(['temp:TLV'], $redis->tsqueryindex('location=TLV')); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testQueryReturnsKeysMatchingGivenFilterExpressionResp3(): void + { + $redis = $this->getResp3Client(); + + $arguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'TLV'); + + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $arguments)); + + $anotherArguments = (new CreateArguments()) + ->labels('type', 'temp', 'location', 'JER'); + + $this->assertEquals('OK', $redis->tscreate('temp:JER', $anotherArguments)); + + $this->assertSame(['temp:TLV'], $redis->tsqueryindex('location=TLV')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSRANGE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSRANGE_Test.php index b4c7b0df..542afd05 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSRANGE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSRANGE_Test.php @@ -83,6 +83,30 @@ class TSRANGE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testReturnsQueriedRangeInForwardDirectionFromGivenTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + + $createArguments = (new CreateArguments())->labels('type', 'temp', 'location', 'TLV'); + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $createArguments)); + + $this->assertSame( + [1000, 1010, 1020, 1030], + $redis->tsmadd('temp:TLV', 1000, 30, 'temp:TLV', 1010, 35, 'temp:TLV', 1020, 9999, 'temp:TLV', 1030, 40) + ); + + $rangeArguments = (new RangeArguments())->filterByValue(-100, 100); + $this->assertEquals( + [[1000, '30'], [1010, '35'], [1030, '40']], + $redis->tsrange('temp:TLV', '-', '+', $rangeArguments) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TimeSeries/TSREVRANGE_Test.php b/tests/Predis/Command/Redis/TimeSeries/TSREVRANGE_Test.php index 1615f5c6..00d297da 100644 --- a/tests/Predis/Command/Redis/TimeSeries/TSREVRANGE_Test.php +++ b/tests/Predis/Command/Redis/TimeSeries/TSREVRANGE_Test.php @@ -83,6 +83,30 @@ class TSREVRANGE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisTimeSeriesVersion >= 1.0.0 + */ + public function testReturnsQueriedRangeInReverseDirectionFromGivenTimeSeriesResp3(): void + { + $redis = $this->getResp3Client(); + + $createArguments = (new CreateArguments())->labels('type', 'temp', 'location', 'TLV'); + $this->assertEquals('OK', $redis->tscreate('temp:TLV', $createArguments)); + + $this->assertSame( + [1000, 1010, 1020, 1030], + $redis->tsmadd('temp:TLV', 1000, 30, 'temp:TLV', 1010, 35, 'temp:TLV', 1020, 9999, 'temp:TLV', 1030, 40) + ); + + $rangeArguments = (new RangeArguments())->filterByValue(-100, 100); + $this->assertEquals( + [[1030, '40'], [1010, '35'], [1000, '30']], + $redis->tsrevrange('temp:TLV', '-', '+', $rangeArguments) + ); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TopK/TOPKADD_Test.php b/tests/Predis/Command/Redis/TopK/TOPKADD_Test.php index 19dd7e03..2de30d2d 100644 --- a/tests/Predis/Command/Redis/TopK/TOPKADD_Test.php +++ b/tests/Predis/Command/Redis/TopK/TOPKADD_Test.php @@ -81,6 +81,21 @@ class TOPKADD_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testAddItemsIntoGivenTopKStructureResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->topkreserve('key', 2); + + $actualResponse = $redis->topkadd('key', 0, 1, 2); + $this->assertEquals([null, null, '0'], $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TopK/TOPKINCRBY_Test.php b/tests/Predis/Command/Redis/TopK/TOPKINCRBY_Test.php index 06f605f2..09040760 100644 --- a/tests/Predis/Command/Redis/TopK/TOPKINCRBY_Test.php +++ b/tests/Predis/Command/Redis/TopK/TOPKINCRBY_Test.php @@ -77,6 +77,24 @@ class TOPKINCRBY_Test extends PredisCommandTestCase $this->assertEquals(['item2' => 3, 'item3' => 3], $redis->topklist('key', true)); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testIncrementItemsScoreOnGivenAmountResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->topkreserve('key', 2); + $this->assertSame([null, null], $redis->topkadd('key', 'item1', 'item2')); + + $actualResponse = $redis->topkincrby('key', 'item1', 1, 'item2', 2, 'item3', 3); + + $this->assertEquals([null, null, 'item1'], $actualResponse); + $this->assertEquals(['item2' => 3, 'item3' => 3], $redis->topklist('key', true)); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TopK/TOPKINFO_Test.php b/tests/Predis/Command/Redis/TopK/TOPKINFO_Test.php index 2a0ca4c9..93278986 100644 --- a/tests/Predis/Command/Redis/TopK/TOPKINFO_Test.php +++ b/tests/Predis/Command/Redis/TopK/TOPKINFO_Test.php @@ -73,9 +73,28 @@ class TOPKINFO_Test extends PredisCommandTestCase $redis->topkreserve('key', 50); - $this->assertEquals( + $this->assertSameWithPrecision( ['k' => 50, 'width' => 8, 'depth' => 7, 'decay' => '0.90000000000000002'], - $redis->topkinfo('key') + $redis->topkinfo('key'), + 1 + ); + } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsInfoAboutGivenTopKStructureResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->topkreserve('key', 50); + + $this->assertSameWithPrecision( + ['k' => 50, 'width' => 8, 'depth' => 7, 'decay' => '0.90000000000000002'], + $redis->topkinfo('key'), + 1 ); } diff --git a/tests/Predis/Command/Redis/TopK/TOPKLIST_Test.php b/tests/Predis/Command/Redis/TopK/TOPKLIST_Test.php index 795a0de3..c5c32937 100644 --- a/tests/Predis/Command/Redis/TopK/TOPKLIST_Test.php +++ b/tests/Predis/Command/Redis/TopK/TOPKLIST_Test.php @@ -87,6 +87,23 @@ class TOPKLIST_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReturnsListOfItemsWithinTopKStructureResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->topkreserve('key', 50); + $redis->topkadd('key', 1, 2, 2, 3, 3, 3); + + $actualResponse = $redis->topklist('key'); + + $this->assertEquals(['3', '2', '1'], $actualResponse); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TopK/TOPKQUERY_Test.php b/tests/Predis/Command/Redis/TopK/TOPKQUERY_Test.php index 721150e0..c079b946 100644 --- a/tests/Predis/Command/Redis/TopK/TOPKQUERY_Test.php +++ b/tests/Predis/Command/Redis/TopK/TOPKQUERY_Test.php @@ -74,6 +74,21 @@ class TOPKQUERY_Test extends PredisCommandTestCase $this->assertSame([1, 0], $redis->topkquery('key', 'item1', 'item2')); } + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testQueryChecksIfItemExistsWithinGivenTopKStructureResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->topkreserve('key', 50); + $redis->topkadd('key', 'item1'); + + $this->assertSame([true, false], $redis->topkquery('key', 'item1', 'item2')); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/TopK/TOPKRESERVE_Test.php b/tests/Predis/Command/Redis/TopK/TOPKRESERVE_Test.php index 08a978ee..879d7359 100644 --- a/tests/Predis/Command/Redis/TopK/TOPKRESERVE_Test.php +++ b/tests/Predis/Command/Redis/TopK/TOPKRESERVE_Test.php @@ -77,7 +77,27 @@ class TOPKRESERVE_Test extends PredisCommandTestCase $actualInfoResponse = $redis->topkinfo($key); $this->assertEquals('OK', $actualResponse); - $this->assertEquals($expectedInfoResponse, $actualInfoResponse); + $this->assertSameWithPrecision($expectedInfoResponse, $actualInfoResponse, 1); + } + + /** + * @group connected + * @return void + * @requiresRedisBfVersion >= 2.6.0 + */ + public function testReserveInitializeTopKStructureWithGivenConfigurationResp3(): void + { + $redis = $this->getResp3Client(); + + $actualResponse = $redis->topkreserve('key', 50); + $actualInfoResponse = $redis->topkinfo('key'); + + $this->assertEquals('OK', $actualResponse); + $this->assertSameWithPrecision( + ['k' => 50, 'width' => 8, 'depth' => 7, 'decay' => '0.90000000000000002'], + $actualInfoResponse, + 1 + ); } /** diff --git a/tests/Predis/Command/Redis/UNSUBSCRIBE_Test.php b/tests/Predis/Command/Redis/UNSUBSCRIBE_Test.php index 20fbc6ab..c191be0c 100644 --- a/tests/Predis/Command/Redis/UNSUBSCRIBE_Test.php +++ b/tests/Predis/Command/Redis/UNSUBSCRIBE_Test.php @@ -13,6 +13,7 @@ namespace Predis\Command\Redis; use Predis\Command\PrefixableCommand; +use Predis\Consumer\Push\PushResponse; /** * @group commands @@ -107,6 +108,19 @@ class UNSUBSCRIBE_Test extends PredisCommandTestCase $this->assertSame('echoed', $redis->echo('echoed')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testDoesNotSwitchToSubscribeModeResp3(): void + { + $redis = $this->getResp3Client(); + $expectedResponse = new PushResponse(['unsubscribe', 'channel', 0]); + + $this->assertEquals($expectedResponse, $redis->unsubscribe('channel')); + $this->assertSame('echoed', $redis->echo('echoed')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/UNWATCH_Test.php b/tests/Predis/Command/Redis/UNWATCH_Test.php index efa9cc8d..e117d015 100644 --- a/tests/Predis/Command/Redis/UNWATCH_Test.php +++ b/tests/Predis/Command/Redis/UNWATCH_Test.php @@ -73,6 +73,26 @@ class UNWATCH_Test extends PredisCommandTestCase $this->assertSame(['hijacked'], $redis1->exec()); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testUnwatchWatchedKeysResp3(): void + { + $redis1 = $this->getResp3Client(); + $redis2 = $this->getResp3Client(); + + $redis1->set('foo', 'bar'); + $redis1->watch('foo'); + $this->assertEquals('OK', $redis1->unwatch()); + $redis1->multi(); + $redis1->get('foo'); + + $redis2->set('foo', 'hijacked'); + + $this->assertSame(['hijacked'], $redis1->exec()); + } + /** * @group connected * @group relay-incompatible diff --git a/tests/Predis/Command/Redis/WATCH_Test.php b/tests/Predis/Command/Redis/WATCH_Test.php index 5fece04e..63c6a5a0 100644 --- a/tests/Predis/Command/Redis/WATCH_Test.php +++ b/tests/Predis/Command/Redis/WATCH_Test.php @@ -109,6 +109,25 @@ class WATCH_Test extends PredisCommandTestCase $this->assertSame('hijacked', $redis1->get('foo')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testAbortsTransactionOnExternalWriteOperationsResp3(): void + { + $redis1 = $this->getResp3Client(); + $redis2 = $this->getResp3Client(); + + $redis1->mset('foo', 'bar', 'hoge', 'piyo'); + + $this->assertEquals('OK', $redis1->watch('foo', 'hoge')); + $this->assertEquals('OK', $redis1->multi()); + $this->assertEquals('QUEUED', $redis1->get('foo')); + $this->assertEquals('OK', $redis2->set('foo', 'hijacked')); + $this->assertNull($redis1->exec()); + $this->assertSame('hijacked', $redis1->get('foo')); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/XADD_Test.php b/tests/Predis/Command/Redis/XADD_Test.php index 78d90bd0..7ebbc2ae 100644 --- a/tests/Predis/Command/Redis/XADD_Test.php +++ b/tests/Predis/Command/Redis/XADD_Test.php @@ -144,6 +144,19 @@ class XADD_Test extends PredisCommandTestCase $this->assertSame(1, $redis->xlen('stream')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testAddsToStreamWithDefaultsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->xadd('stream', ['key' => 'val']); + + $this->assertSame(1, $redis->xlen('stream')); + } + /** * @group connected * @requiresRedisVersion >= 5.0.0 diff --git a/tests/Predis/Command/Redis/XDEL_Test.php b/tests/Predis/Command/Redis/XDEL_Test.php index 787d04e4..8c52a388 100644 --- a/tests/Predis/Command/Redis/XDEL_Test.php +++ b/tests/Predis/Command/Redis/XDEL_Test.php @@ -93,6 +93,24 @@ class XDEL_Test extends PredisCommandTestCase $this->assertSame(0, $redis->xdel('stream', '0-1')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesSpecifiedMembersResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->xadd('stream', ['key0' => 'val0'], '0-1'); + $redis->xadd('stream', ['key1' => 'val1'], '1-1'); + $redis->xadd('stream', ['key2' => 'val2'], '2-1'); + + $this->assertSame(2, $redis->xdel('stream', '0-1', '2-1', '99-1')); + $this->assertSame(['1-1' => ['key1' => 'val1']], $redis->xrange('stream', '-', '+')); + + $this->assertSame(0, $redis->xdel('stream', '0-1')); + } + /** * @group connected * @requiresRedisVersion >= 5.0.0 diff --git a/tests/Predis/Command/Redis/XLEN_Test.php b/tests/Predis/Command/Redis/XLEN_Test.php index 1fae1a3e..6fc207a4 100644 --- a/tests/Predis/Command/Redis/XLEN_Test.php +++ b/tests/Predis/Command/Redis/XLEN_Test.php @@ -91,6 +91,22 @@ class XLEN_Test extends PredisCommandTestCase $this->assertSame(3, $redis->xlen('stream')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsLengthOfListResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->xadd('stream', ['key' => 'val']); + $redis->xadd('stream', ['key' => 'val']); + $this->assertSame(2, $redis->xlen('stream')); + + $redis->xadd('stream', ['key' => 'val']); + $this->assertSame(3, $redis->xlen('stream')); + } + /** * @group connected * @requiresRedisVersion >= 5.0.0 diff --git a/tests/Predis/Command/Redis/XRANGE_Test.php b/tests/Predis/Command/Redis/XRANGE_Test.php index 90ded890..ec51899d 100644 --- a/tests/Predis/Command/Redis/XRANGE_Test.php +++ b/tests/Predis/Command/Redis/XRANGE_Test.php @@ -162,6 +162,26 @@ class XRANGE_Test extends PredisCommandTestCase ); } + /** + * @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( + [ + '0-1' => ['key1' => 'val1', 'key2' => 'val2'], + '1-1' => ['key1' => 'val1', 'key2' => 'val2'], + ], + $redis->xrange('stream', '-', '+') + ); + } + /** * @group connected * @requiresRedisVersion >= 5.0.0 diff --git a/tests/Predis/Command/Redis/XREVRANGE_Test.php b/tests/Predis/Command/Redis/XREVRANGE_Test.php index 0e264317..7e970d93 100644 --- a/tests/Predis/Command/Redis/XREVRANGE_Test.php +++ b/tests/Predis/Command/Redis/XREVRANGE_Test.php @@ -162,6 +162,26 @@ class XREVRANGE_Test extends PredisCommandTestCase ); } + /** + * @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 diff --git a/tests/Predis/Command/Redis/XTRIM_Test.php b/tests/Predis/Command/Redis/XTRIM_Test.php index 1e8d1bc5..95440eeb 100644 --- a/tests/Predis/Command/Redis/XTRIM_Test.php +++ b/tests/Predis/Command/Redis/XTRIM_Test.php @@ -113,6 +113,24 @@ class XTRIM_Test extends PredisCommandTestCase $this->assertSame(2, $redis->xlen('stream')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testTrimOnMaxlenExactResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->xadd('stream', ['key' => 'val']); + $redis->xadd('stream', ['key' => 'val']); + $redis->xadd('stream', ['key' => 'val']); + + $res = $redis->xtrim('stream', 'MAXLEN', 2); + + $this->assertSame(1, $res); + $this->assertSame(2, $redis->xlen('stream')); + } + /** * @group connected * @requiresRedisVersion >= 5.0.0 diff --git a/tests/Predis/Command/Redis/ZADD_Test.php b/tests/Predis/Command/Redis/ZADD_Test.php index 4f46cdc9..10571f2c 100644 --- a/tests/Predis/Command/Redis/ZADD_Test.php +++ b/tests/Predis/Command/Redis/ZADD_Test.php @@ -117,6 +117,21 @@ class ZADD_Test extends PredisCommandTestCase $this->assertSame(['a', 'e', 'b', 'd', 'f', 'c'], $redis->zrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testAddsOrUpdatesMembersOrderingByScoreResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(5, $redis->zadd('letters', 1, 'a', 2, 'b', 3, 'c', 4, 'd', 5, 'e')); + $this->assertSame(['a', 'b', 'c', 'd', 'e'], $redis->zrange('letters', 0, -1)); + + $this->assertSame(1, $redis->zadd('letters', 1, 'e', 8, 'c', 6, 'f')); + $this->assertSame(['a', 'e', 'b', 'd', 'f', 'c'], $redis->zrange('letters', 0, -1)); + } + /** * @group connected * @requiresRedisVersion >= 3.0.2 diff --git a/tests/Predis/Command/Redis/ZCARD_Test.php b/tests/Predis/Command/Redis/ZCARD_Test.php index 84146ba1..b5d8be68 100644 --- a/tests/Predis/Command/Redis/ZCARD_Test.php +++ b/tests/Predis/Command/Redis/ZCARD_Test.php @@ -88,6 +88,20 @@ class ZCARD_Test extends PredisCommandTestCase $this->assertSame(0, $redis->zcard('unknown')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsSizeOfSortedSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', 1, 'a', 2, 'b', 3, 'c'); + $this->assertSame(3, $redis->zcard('letters')); + + $this->assertSame(0, $redis->zcard('unknown')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZCOUNT_Test.php b/tests/Predis/Command/Redis/ZCOUNT_Test.php index 09e3a6d0..54aa9de2 100644 --- a/tests/Predis/Command/Redis/ZCOUNT_Test.php +++ b/tests/Predis/Command/Redis/ZCOUNT_Test.php @@ -94,6 +94,25 @@ class ZCOUNT_Test extends PredisCommandTestCase $this->assertSame(0, $redis->zcount('unknown', 0, 100)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsNumberOfElementsInGivenScoreRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', 10, 'a', 20, 'b', 30, 'c', 40, 'd', 50, 'e'); + + $this->assertSame(5, $redis->zcount('letters', 0, 100)); + $this->assertSame(5, $redis->zcount('letters', -100, 100)); + $this->assertSame(2, $redis->zcount('letters', 25, 45)); + $this->assertSame(1, $redis->zcount('letters', 20, 20)); + $this->assertSame(0, $redis->zcount('letters', 0, 0)); + + $this->assertSame(0, $redis->zcount('unknown', 0, 100)); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ZDIFFSTORE_Test.php b/tests/Predis/Command/Redis/ZDIFFSTORE_Test.php index b3aa05ab..19be26b7 100644 --- a/tests/Predis/Command/Redis/ZDIFFSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZDIFFSTORE_Test.php @@ -78,6 +78,23 @@ class ZDIFFSTORE_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->zrange('zdiffstore', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testStoresDifferenceBetweenSortedSetsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zset-1', 1, 'member1', 2, 'member2', 3, 'member3'); + $redis->zadd('test-zset-2', 1, 'member4', 2, 'member5', 3, 'member6'); + $actualResponse = $redis->zdiffstore('zdiffstore', ['test-zset-1', 'test-zset-2']); + + $this->assertSame(3, $actualResponse); + $this->assertSame(['member1', 'member2', 'member3'], $redis->zrange('zdiffstore', 0, -1)); + } + public function sortedSetsProvider(): array { return [ diff --git a/tests/Predis/Command/Redis/ZDIFF_test.php b/tests/Predis/Command/Redis/ZDIFF_test.php index e7d61434..e4abaab1 100644 --- a/tests/Predis/Command/Redis/ZDIFF_test.php +++ b/tests/Predis/Command/Redis/ZDIFF_test.php @@ -91,6 +91,21 @@ class ZDIFF_test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->zdiff(['test-zset-1', 'test-zset-2'], true)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsNoIntersectionOnNonExistingKeyResp3(): void + { + $redis = $this->getResp3Client(); + $membersDictionary = [1, 'member1', 2, 'member2', 3, 'member3']; + $expectedResponse = [['member1' => 1.0], ['member2' => 2.0], ['member3' => 3.0]]; + + $redis->zadd('test-zset-1', ...$membersDictionary); + $this->assertSame($expectedResponse, $redis->zdiff(['test-zset-1', 'test-zset-2'], true)); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Command/Redis/ZINCRBY_Test.php b/tests/Predis/Command/Redis/ZINCRBY_Test.php index d2884343..3fa9c928 100644 --- a/tests/Predis/Command/Redis/ZINCRBY_Test.php +++ b/tests/Predis/Command/Redis/ZINCRBY_Test.php @@ -88,6 +88,20 @@ class ZINCRBY_Test extends PredisCommandTestCase $this->assertEquals('-10', $redis->zincrby('letters', -10.5, 'member')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testIncrementsScoreOfMemberByFloatResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame(1.0, $redis->zincrby('letters', 1, 'member')); + $this->assertSame(0.0, $redis->zincrby('letters', -1, 'member')); + $this->assertSame(0.5, $redis->zincrby('letters', 0.5, 'member')); + $this->assertSame(-10.0, $redis->zincrby('letters', -10.5, 'member')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZINTERCARD_Test.php b/tests/Predis/Command/Redis/ZINTERCARD_Test.php index 7923b4d8..9085b095 100644 --- a/tests/Predis/Command/Redis/ZINTERCARD_Test.php +++ b/tests/Predis/Command/Redis/ZINTERCARD_Test.php @@ -77,6 +77,21 @@ class ZINTERCARD_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->zintercard(['test-zintercard1', 'test-zintercard2'], $limit)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsIntersectionCardinalityOnSortedSetsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zintercard1', 1, 'member1', 2, 'member2', 3, 'member3'); + $redis->zadd('test-zintercard2', 1, 'member1', 2, 'member2', 3, 'member3'); + + $this->assertSame(3, $redis->zintercard(['test-zintercard1', 'test-zintercard2'])); + } + /** * @group connected * @return void diff --git a/tests/Predis/Command/Redis/ZINTERSTORE_Test.php b/tests/Predis/Command/Redis/ZINTERSTORE_Test.php index bad586c1..f3773b9f 100644 --- a/tests/Predis/Command/Redis/ZINTERSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZINTERSTORE_Test.php @@ -116,6 +116,27 @@ class ZINTERSTORE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.0.0 + */ + public function testStoresIntersectedValuesOnSortedSetsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zunionstore1', 1, 'member1', 2, 'member2', 3, 'member3'); + $redis->zadd('test-zunionstore2', 1, 'member1', 2, 'member2'); + + $actualResponse = $redis->zinterstore('destination', ['test-zunionstore1', 'test-zunionstore2']); + + $this->assertSame(2, $actualResponse); + $this->assertSame( + [['member1' => 2.0], ['member2' => 4.0]], + $redis->zrange('destination', 0, -1, ['withscores' => true]) + ); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ZINTER_Test.php b/tests/Predis/Command/Redis/ZINTER_Test.php index 22eaef5b..9f8c6b54 100644 --- a/tests/Predis/Command/Redis/ZINTER_Test.php +++ b/tests/Predis/Command/Redis/ZINTER_Test.php @@ -110,6 +110,23 @@ class ZINTER_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsIntersectedValuesOnSortedSetsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zinter1', 1, 'member1', 2, 'member2', 3, 'member3'); + $redis->zadd('test-zinter2', 1, 'member1', 2, 'member2'); + + $actualResponse = $redis->zinter(['test-zinter1', 'test-zinter2']); + + $this->assertSame(['member1', 'member2'], $actualResponse); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php b/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php index d1090b34..5cbddc38 100644 --- a/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php +++ b/tests/Predis/Command/Redis/ZLEXCOUNT_Test.php @@ -91,6 +91,22 @@ class ZLEXCOUNT_Test extends PredisCommandTestCase $this->assertSame(0, $redis->zlexcount('letters', '(f', '(b')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testExclusiveIntervalRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); + + $this->assertSame(3, $redis->zlexcount('letters', '(b', '(f')); + $this->assertSame(5, $redis->zlexcount('letters', '(b', '(z')); + $this->assertSame(4, $redis->zlexcount('letters', '(0', '(e')); + $this->assertSame(0, $redis->zlexcount('letters', '(f', '(b')); + } + /** * @group connected * @requiresRedisVersion >= 2.8.9 diff --git a/tests/Predis/Command/Redis/ZMPOP_Test.php b/tests/Predis/Command/Redis/ZMPOP_Test.php index 6d52005f..0724fe34 100644 --- a/tests/Predis/Command/Redis/ZMPOP_Test.php +++ b/tests/Predis/Command/Redis/ZMPOP_Test.php @@ -64,7 +64,7 @@ class ZMPOP_Test extends PredisCommandTestCase * @param array $expectedResponse * @param array $expectedModifiedSortedSet * @return void - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 */ public function testReturnsPoppedElementsFromGivenSortedSet( array $sortedSetDictionary, @@ -86,7 +86,23 @@ class ZMPOP_Test extends PredisCommandTestCase /** * @group connected * @return void - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsPoppedElementsFromGivenSortedSetResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zmpop', 1, 'member1', 2, 'member2', 3, 'member3'); + $actualResponse = $redis->zmpop(['test-zmpop']); + + $this->assertSame(['test-zmpop' => ['member1' => 1.0]], $actualResponse); + $this->assertSame(['member2', 'member3'], $redis->zrange('test-zmpop', 0, -1)); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 */ public function testReturnsPoppedElementsFromFirstNonEmptySortedSet(): void { @@ -110,7 +126,7 @@ class ZMPOP_Test extends PredisCommandTestCase * @param int $count * @param string $expectedExceptionMessage * @return void - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 */ public function testThrowsExceptionOnUnexpectedValueGiven( array $keys, @@ -128,7 +144,7 @@ class ZMPOP_Test extends PredisCommandTestCase /** * @group connected - * @requiresRedisVersion >= 7.0 + * @requiresRedisVersion >= 7.0.0 */ public function testThrowsExceptionOnWrongType(): void { diff --git a/tests/Predis/Command/Redis/ZMSCORE_Test.php b/tests/Predis/Command/Redis/ZMSCORE_Test.php index db1d0941..e1d04a75 100644 --- a/tests/Predis/Command/Redis/ZMSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZMSCORE_Test.php @@ -82,6 +82,27 @@ class ZMSCORE_Test extends PredisCommandTestCase $this->assertNull($redis->zmscore($key, $notExpectedMember)[0]); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsScoresAssociatedWithMembersResp3(): void + { + $redis = $this->getResp3Client(); + $notExpectedMember = 'not_expected'; + + /** @var string[] $members */ + $members = array_filter([1, 'member1', 2, 'member2', 3, 'member3'], static function ($item) { + return is_string($item); + }); + + $redis->zadd('test-zscore', 1, 'member1', 2, 'member2', 3, 'member3'); + + $this->assertSame([1.0, 2.0, 3.0], $redis->zmscore('test-zscore', ...$members)); + $this->assertNull($redis->zmscore('test-zscore', $notExpectedMember)[0]); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Command/Redis/ZPOPMAX_Test.php b/tests/Predis/Command/Redis/ZPOPMAX_Test.php index dad4dde4..8d50ca60 100644 --- a/tests/Predis/Command/Redis/ZPOPMAX_Test.php +++ b/tests/Predis/Command/Redis/ZPOPMAX_Test.php @@ -83,6 +83,25 @@ class ZPOPMAX_Test extends PredisCommandTestCase $this->assertEquals(['b' => '0', 'a' => '-10'], $redis->zpopmax('letters', 3)); } + /** + * @requiresRedisVersion >= 6.0.0 + * + * @group connected + */ + public function testReturnsElementsResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame([], $redis->zpopmax('letters')); + $this->assertSame([], $redis->zpopmax('letters', 3)); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(['f' => 30.0], $redis->zpopmax('letters')); + $this->assertSame([['e' => 20.0], ['d' => 20.0], ['c' => 10.0]], $redis->zpopmax('letters', 3)); + $this->assertSame([['b' => 0.0], ['a' => -10.0]], $redis->zpopmax('letters', 3)); + } + /** * @requiresRedisVersion >= 5.0.0 * diff --git a/tests/Predis/Command/Redis/ZPOPMIN_Test.php b/tests/Predis/Command/Redis/ZPOPMIN_Test.php index 43849803..3f4ad288 100644 --- a/tests/Predis/Command/Redis/ZPOPMIN_Test.php +++ b/tests/Predis/Command/Redis/ZPOPMIN_Test.php @@ -83,6 +83,25 @@ class ZPOPMIN_Test extends PredisCommandTestCase $this->assertEquals(['e' => '20', 'f' => '30'], $redis->zpopmin('letters', 3)); } + /** + * @requiresRedisVersion >= 6.0.0 + * + * @group connected + */ + public function testReturnsElementsResp3(): void + { + $redis = $this->getResp3Client(); + + $this->assertSame([], $redis->zpopmin('letters')); + $this->assertSame([], $redis->zpopmin('letters', 3)); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(['a' => -10.0], $redis->zpopmin('letters')); + $this->assertSame([['b' => 0.0], ['c' => 10.0], ['d' => 20.0]], $redis->zpopmin('letters', 3)); + $this->assertSame([['e' => 20.0], ['f' => 30.0]], $redis->zpopmin('letters', 3)); + } + /** * @requiresRedisVersion >= 5.0.0 * diff --git a/tests/Predis/Command/Redis/ZRANDMEMBER_test.php b/tests/Predis/Command/Redis/ZRANDMEMBER_test.php index 634ffc31..999c93ba 100644 --- a/tests/Predis/Command/Redis/ZRANDMEMBER_test.php +++ b/tests/Predis/Command/Redis/ZRANDMEMBER_test.php @@ -78,6 +78,21 @@ class ZRANDMEMBER_test extends PredisCommandTestCase $this->assertNull($redis->zrandmember($notExpectedKey)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsRandomMembersFromSortedSetResp3(): void + { + $redis = $this->getResp3Client(); + $notExpectedKey = 'not_expected'; + + $redis->zadd('test-zset', 1, 'member1'); + $this->assertSame('member1', $redis->zrandmember('test-zset')); + $this->assertNull($redis->zrandmember($notExpectedKey)); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php b/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php index 2ced5f6b..3c384c71 100644 --- a/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php +++ b/tests/Predis/Command/Redis/ZRANGEBYLEX_Test.php @@ -100,11 +100,11 @@ class ZRANGEBYLEX_Test extends PredisCommandTestCase /** * @group connected - * @requiresRedisVersion >= 2.8.9 + * @requiresRedisVersion >= 6.0.0 */ - public function testReturnsElementsInWholeRange(): void + public function testReturnsElementsInWholeRangeResp3(): void { - $redis = $this->getClient(); + $redis = $this->getResp3Client(); $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); diff --git a/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php b/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php index bc7d11b9..3003c76a 100644 --- a/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGEBYSCORE_Test.php @@ -161,6 +161,24 @@ class ZRANGEBYSCORE_Test extends PredisCommandTestCase $this->assertSame([], $redis->zrangebyscore('unknown', 0, 30)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementsInScoreRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(['a'], $redis->zrangebyscore('letters', -10, -10)); + $this->assertSame(['c', 'd', 'e', 'f'], $redis->zrangebyscore('letters', 10, 30)); + $this->assertSame(['d', 'e'], $redis->zrangebyscore('letters', 20, 20)); + $this->assertSame([], $redis->zrangebyscore('letters', 30, 0)); + + $this->assertSame([], $redis->zrangebyscore('unknown', 0, 30)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZRANGESTORE_Test.php b/tests/Predis/Command/Redis/ZRANGESTORE_Test.php index 2989a3ed..67351c32 100644 --- a/tests/Predis/Command/Redis/ZRANGESTORE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGESTORE_Test.php @@ -99,6 +99,27 @@ class ZRANGESTORE_Test extends PredisCommandTestCase $this->assertSame($expectedResponse, $redis->zrange('destination', 0, -1)); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.0.0 + */ + public function testStoresSortedSetRangesResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('source', 1, 'member1', 2, 'member2', 3, 'member3'); + $actualResponse = $redis->zrangestore( + 'destination', + 'source', + 0, + -1 + ); + + $this->assertSame(3, $actualResponse); + $this->assertSame(['member1', 'member2', 'member3'], $redis->zrange('destination', 0, -1)); + } + /** * @group connected * @dataProvider unexpectedValuesProvider diff --git a/tests/Predis/Command/Redis/ZRANGE_Test.php b/tests/Predis/Command/Redis/ZRANGE_Test.php index 6e8b6fea..d5cec557 100644 --- a/tests/Predis/Command/Redis/ZRANGE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGE_Test.php @@ -146,6 +146,28 @@ class ZRANGE_Test extends PredisCommandTestCase $this->assertSame([], $redis->zrange('unknown', 0, 30)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementsInRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame([], $redis->zrange('letters', 1, 0)); + $this->assertSame(['a'], $redis->zrange('letters', 0, 0)); + $this->assertSame(['a', 'b', 'c', 'd'], $redis->zrange('letters', 0, 3)); + + $this->assertSame(['a', 'b', 'c', 'd', 'e', 'f'], $redis->zrange('letters', 0, -1)); + $this->assertSame(['a', 'b', 'c'], $redis->zrange('letters', 0, -4)); + $this->assertSame(['c'], $redis->zrange('letters', 2, -4)); + $this->assertSame(['a', 'b', 'c', 'd', 'e', 'f'], $redis->zrange('letters', -100, 100)); + + $this->assertSame([], $redis->zrange('unknown', 0, 30)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZRANK_Test.php b/tests/Predis/Command/Redis/ZRANK_Test.php index 73ac5d5f..b8506e73 100644 --- a/tests/Predis/Command/Redis/ZRANK_Test.php +++ b/tests/Predis/Command/Redis/ZRANK_Test.php @@ -92,6 +92,23 @@ class ZRANK_Test extends PredisCommandTestCase $this->assertNull($redis->zrank('unknown', 'a')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsRankResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(0, $redis->zrank('letters', 'a')); + $this->assertSame(1, $redis->zrank('letters', 'b')); + $this->assertSame(4, $redis->zrank('letters', 'e')); + + $this->assertNull($redis->zrank('unknown', 'a')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php b/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php index 7cf63417..e2a33ac4 100644 --- a/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php +++ b/tests/Predis/Command/Redis/ZREMRANGEBYLEX_Test.php @@ -91,6 +91,22 @@ class ZREMRANGEBYLEX_Test extends PredisCommandTestCase $this->assertSame([], $redis->zrange('letters', 0, -1)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesRangeByLexWithWholeRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); + + $this->assertSame(0, $redis->zremrangebylex('letters', '+', '-')); + $this->assertSame(7, $redis->zremrangebylex('letters', '-', '+')); + + $this->assertSame([], $redis->zrange('letters', 0, -1)); + } + /** * @group connected * @requiresRedisVersion >= 2.8.9 diff --git a/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php b/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php index 5ca34e43..91048c73 100644 --- a/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php +++ b/tests/Predis/Command/Redis/ZREMRANGEBYRANK_Test.php @@ -91,6 +91,22 @@ class ZREMRANGEBYRANK_Test extends PredisCommandTestCase $this->assertSame(0, $redis->zremrangebyrank('unknown', 0, 30)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesRangeByRankResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(3, $redis->zremrangebyrank('letters', 2, 4)); + $this->assertSame(['a', 'b', 'f'], $redis->zrange('letters', 0, -1)); + + $this->assertSame(0, $redis->zremrangebyrank('unknown', 0, 30)); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php b/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php index 83a3bd77..e19df54c 100644 --- a/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZREMRANGEBYSCORE_Test.php @@ -90,6 +90,22 @@ class ZREMRANGEBYSCORE_Test extends PredisCommandTestCase $this->assertSame(0, $redis->zremrangebyscore('unknown', 0, 30)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesRangeByScoreResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(3, $redis->zremrangebyscore('letters', 5, 20)); + $this->assertSame(['a', 'b', 'f'], $redis->zrange('letters', 0, -1)); + + $this->assertSame(0, $redis->zremrangebyscore('unknown', 0, 30)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZREM_Test.php b/tests/Predis/Command/Redis/ZREM_Test.php index e71ec865..0a27c8a6 100644 --- a/tests/Predis/Command/Redis/ZREM_Test.php +++ b/tests/Predis/Command/Redis/ZREM_Test.php @@ -90,6 +90,22 @@ class ZREM_Test extends PredisCommandTestCase $this->assertSame(0, $redis->zrem('unknown', 'a')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testRemovesSpecifiedMembersResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(3, $redis->zrem('letters', 'b', 'd', 'f', 'z')); + $this->assertSame(['a', 'c', 'e'], $redis->zrange('letters', 0, -1)); + + $this->assertSame(0, $redis->zrem('unknown', 'a')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php b/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php index 6ace2588..aabdf075 100644 --- a/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANGEBYLEX_Test.php @@ -114,6 +114,22 @@ class ZREVRANGEBYLEX_Test extends PredisCommandTestCase $this->assertSame([], $redis->zrevrangebylex('unknown', '+', '-')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementsInWholeRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', 0, 'a', 0, 'b', 0, 'c', 0, 'd', 0, 'e', 0, 'f', 0, 'g'); + + $this->assertSame(['g', 'f', 'e', 'd', 'c', 'b', 'a'], $redis->zrevrangebylex('letters', '+', '-')); + $this->assertSame([], $redis->zrevrangebylex('letters', '-', '+')); + $this->assertSame([], $redis->zrevrangebylex('unknown', '-', '+')); + $this->assertSame([], $redis->zrevrangebylex('unknown', '+', '-')); + } + /** * @group connected * @requiresRedisVersion >= 2.8.9 diff --git a/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php b/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php index 7b9e03a2..ffe797b4 100644 --- a/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANGEBYSCORE_Test.php @@ -162,6 +162,24 @@ class ZREVRANGEBYSCORE_Test extends PredisCommandTestCase $this->assertSame([], $redis->zrevrangebyscore('unknown', 0, 30)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementsInScoreRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(['a'], $redis->zrevrangebyscore('letters', -10, -10)); + $this->assertSame([], $redis->zrevrangebyscore('letters', 10, 30)); + $this->assertSame(['e', 'd'], $redis->zrevrangebyscore('letters', 20, 20)); + $this->assertSame(['f', 'e', 'd', 'c', 'b'], $redis->zrevrangebyscore('letters', 30, 0)); + + $this->assertSame([], $redis->zrevrangebyscore('unknown', 0, 30)); + } + /** * @group connected * @requiresRedisVersion >= 2.2.0 diff --git a/tests/Predis/Command/Redis/ZREVRANGE_Test.php b/tests/Predis/Command/Redis/ZREVRANGE_Test.php index ab52a7a7..0eb5d86f 100644 --- a/tests/Predis/Command/Redis/ZREVRANGE_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANGE_Test.php @@ -146,6 +146,28 @@ class ZREVRANGE_Test extends PredisCommandTestCase $this->assertSame([], $redis->zrevrange('unknown', 0, 30)); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsElementsInRangeResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame([], $redis->zrevrange('letters', 1, 0)); + $this->assertSame(['f'], $redis->zrevrange('letters', 0, 0)); + $this->assertSame(['f', 'e', 'd', 'c'], $redis->zrevrange('letters', 0, 3)); + + $this->assertSame(['f', 'e', 'd', 'c', 'b', 'a'], $redis->zrevrange('letters', 0, -1)); + $this->assertSame(['f', 'e', 'd'], $redis->zrevrange('letters', 0, -4)); + $this->assertSame(['d'], $redis->zrevrange('letters', 2, -4)); + $this->assertSame(['f', 'e', 'd', 'c', 'b', 'a'], $redis->zrevrange('letters', -100, 100)); + + $this->assertSame([], $redis->zrevrange('unknown', 0, 30)); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZREVRANK_Test.php b/tests/Predis/Command/Redis/ZREVRANK_Test.php index 1946c067..6ca8e8d6 100644 --- a/tests/Predis/Command/Redis/ZREVRANK_Test.php +++ b/tests/Predis/Command/Redis/ZREVRANK_Test.php @@ -92,6 +92,23 @@ class ZREVRANK_Test extends PredisCommandTestCase $this->assertNull($redis->zrevrank('unknown', 'a')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsRankResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(5, $redis->zrevrank('letters', 'a')); + $this->assertSame(4, $redis->zrevrank('letters', 'b')); + $this->assertSame(1, $redis->zrevrank('letters', 'e')); + + $this->assertNull($redis->zrevrank('unknown', 'a')); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ZSCAN_Test.php b/tests/Predis/Command/Redis/ZSCAN_Test.php index 629f27fe..3fe37cf9 100644 --- a/tests/Predis/Command/Redis/ZSCAN_Test.php +++ b/tests/Predis/Command/Redis/ZSCAN_Test.php @@ -127,6 +127,25 @@ class ZSCAN_Test extends PredisCommandTestCase $this->assertSame($expectedScores, array_values($response[1])); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testScanWithoutMatchResp3(): void + { + $expectedMembers = ['member:one', 'member:two', 'member:three', 'member:four']; + $expectedScores = [1.0, 2.0, 3.0, 4.0]; + + $redis = $this->getResp3Client(); + $redis->zadd('key', array_combine($expectedMembers, $expectedScores)); + + $response = $redis->zscan('key', 0); + + $this->assertSame('0', $response[0]); + $this->assertSame($expectedMembers, array_keys($response[1])); + $this->assertSame($expectedScores, array_values($response[1])); + } + /** * @group connected * @requiresRedisVersion >= 2.8.0 diff --git a/tests/Predis/Command/Redis/ZSCORE_Test.php b/tests/Predis/Command/Redis/ZSCORE_Test.php index 1d0fcf03..67118a46 100644 --- a/tests/Predis/Command/Redis/ZSCORE_Test.php +++ b/tests/Predis/Command/Redis/ZSCORE_Test.php @@ -91,6 +91,23 @@ class ZSCORE_Test extends PredisCommandTestCase $this->assertNull($redis->zscore('unknown', 'a')); } + /** + * @group connected + * @requiresRedisVersion >= 6.0.0 + */ + public function testReturnsRankResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('letters', -10, 'a', 0, 'b', 10, 'c', 20, 'd', 20, 'e', 30, 'f'); + + $this->assertSame(-10.0, $redis->zscore('letters', 'a')); + $this->assertSame(0.0, $redis->zscore('letters', 'b')); + $this->assertSame(20.0, $redis->zscore('letters', 'e')); + + $this->assertNull($redis->zscore('unknown', 'a')); + } + /** * @group connected */ diff --git a/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php b/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php index 2d9e8532..46bd18c8 100644 --- a/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php @@ -116,6 +116,27 @@ class ZUNIONSTORE_Test extends PredisCommandTestCase ); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.0.0 + */ + public function testStoresUnionValuesOnSortedSetsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zunionstore1', 1, 'member1', 2, 'member2', 3, 'member3'); + $redis->zadd('test-zunionstore2', 1, 'member1', 2, 'member2'); + + $actualResponse = $redis->zunionstore('destination', ['test-zunionstore1', 'test-zunionstore2']); + + $this->assertSame(3, $actualResponse); + $this->assertSame( + [['member1' => 2.0], ['member3' => 3.0], ['member2' => 4.0]], + $redis->zrange('destination', 0, -1, ['withscores' => true]) + ); + } + /** * @group connected * @requiresRedisVersion >= 2.0.0 diff --git a/tests/Predis/Command/Redis/ZUNION_Test.php b/tests/Predis/Command/Redis/ZUNION_Test.php index 0cd033c9..938f7896 100644 --- a/tests/Predis/Command/Redis/ZUNION_Test.php +++ b/tests/Predis/Command/Redis/ZUNION_Test.php @@ -84,6 +84,23 @@ class ZUNION_Test extends PredisCommandTestCase $this->assertEquals($expectedResponse, $actualResponse); } + /** + * @group connected + * @return void + * @requiresRedisVersion >= 6.2.0 + */ + public function testReturnsIntersectedValuesOnSortedSetsResp3(): void + { + $redis = $this->getResp3Client(); + + $redis->zadd('test-zunion1', 1, 'member1', 2, 'member2', 3, 'member3'); + $redis->zadd('test-zunion2', 1, 'member1', 2, 'member2'); + + $actualResponse = $redis->zunion(['test-zunion1', 'test-zunion2']); + + $this->assertSame(['member1', 'member3', 'member2'], $actualResponse); + } + /** * @group connected * @requiresRedisVersion >= 6.2.0 diff --git a/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php b/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php index 16db9267..60721c10 100644 --- a/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php +++ b/tests/Predis/Protocol/Parser/Strategy/Resp3StrategyTest.php @@ -104,7 +104,10 @@ class Resp3StrategyTest extends PredisTestCase $actualResponse = $this->strategy->parseData($data); - $this->assertSame(['type' => 'verbatimString', 'value' => 15], $actualResponse); + $this->assertSame( + ['type' => 'verbatimString', 'value' => 15, 'offset' => Resp3Strategy::VERBATIM_STRING_EXTENSION_OFFSET], + $actualResponse + ); } /** diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1e21c357..be3b405a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -20,6 +20,7 @@ if (file_exists(__DIR__ . '/../autoload.php')) { require __DIR__ . '/PHPUnit/ArrayHasSameValuesConstraint.php'; require __DIR__ . '/PHPUnit/OneOfConstraint.php'; +require __DIR__ . '/PHPUnit/AssertSameWithPrecisionConstraint.php'; require __DIR__ . '/PHPUnit/RedisCommandConstraint.php'; require __DIR__ . '/PHPUnit/PredisTestCase.php'; require __DIR__ . '/PHPUnit/PredisCommandTestCase.php';