diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 7541e24b..97f133b0 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -153,6 +153,7 @@ use Predis\Command\CommandInterface; * @method $this zrevrangebylex($key, $start, $stop, array $options = null) * @method $this zremrangebylex($key, $min, $max) * @method $this zlexcount($key, $min, $max) + * @method $this pexpiretime(string $key) * @method $this pfadd($key, array $elements) * @method $this pfmerge($destinationKey, array|string $sourceKeys) * @method $this pfcount(array|string $keys) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 79f8595e..73e61310 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -171,6 +171,7 @@ use Predis\Response\Status; * @method array zrevrangebylex(string $key, string $start, string $stop, array $options = null) * @method int zremrangebylex(string $key, string $min, string $max) * @method int zlexcount(string $key, string $min, string $max) + * @method int pexpiretime(string $key) * @method int pfadd(string $key, array $elements) * @method mixed pfmerge(string $destinationKey, array|string $sourceKeys) * @method int pfcount(string[]|string $keyOrKeys, string ...$keys = null) diff --git a/src/Command/Redis/PEXPIRETIME.php b/src/Command/Redis/PEXPIRETIME.php new file mode 100644 index 00000000..de128969 --- /dev/null +++ b/src/Command/Redis/PEXPIRETIME.php @@ -0,0 +1,29 @@ +getCommand(); + $command->setArguments($arguments); + + $this->assertSame($expected, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @return void + * @requiresRedisVersion >= 7.0.0 + */ + public function testReturnsCorrectExpirationTimeForGivenKey(): void + { + $redis = $this->getClient(); + $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('non-existing key')); + } +}