diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 97f133b0..5a8d2803 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -26,6 +26,7 @@ use Predis\Command\CommandInterface; * @method $this exists($key) * @method $this expire($key, $seconds) * @method $this expireat($key, $timestamp) + * @method $this expiretime(string $key) * @method $this keys($pattern) * @method $this move($key, $db) * @method $this object($subcommand, $key) diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 73e61310..60271d96 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -35,6 +35,7 @@ use Predis\Response\Status; * @method int exists(string $key) * @method int expire(string $key, int $seconds) * @method int expireat(string $key, int $timestamp) + * @method int expiretime(string $key) * @method array keys(string $pattern) * @method int move(string $key, int $db) * @method mixed object($subcommand, string $key) diff --git a/src/Command/Redis/EXPIRETIME.php b/src/Command/Redis/EXPIRETIME.php new file mode 100644 index 00000000..8825589d --- /dev/null +++ b/src/Command/Redis/EXPIRETIME.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 testReturnsCorrectKeyExpirationTime(): void + { + $expirationTime = (int) microtime(true) + 100000; + $redis = $this->getClient(); + + $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')); + } +}