From b28cac64f82d77a222880cca069a8a3d5b46e445 Mon Sep 17 00:00:00 2001 From: Zike Date: Mon, 26 Dec 2022 15:52:06 -0500 Subject: [PATCH 1/3] Update Redis.zep add ttl() and pttl() to that developer can get Redis TTL. --- phalcon/Storage/Adapter/Redis.zep | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/phalcon/Storage/Adapter/Redis.zep b/phalcon/Storage/Adapter/Redis.zep index ad1bb7caa99..bf40d9ee6ae 100644 --- a/phalcon/Storage/Adapter/Redis.zep +++ b/phalcon/Storage/Adapter/Redis.zep @@ -68,6 +68,32 @@ class Redis extends AbstractAdapter parent::__construct(factory, options); } + /** + * Returns the time to live left for a given key in seconds + * + * @param string $key + * LONG: The time to live in seconds. If the key has no ttl, -1 will be returned, and -2 if the key doesn't exist. + * @return int + * @throws StorageException + */ + public function ttl($key) -> int + { + return this->getAdapter()->ttl(key); + } + + /** + * Returns the time to live left for a given key in milliseconds + * + * @param string $key + * + * @return int + * @throws StorageException + */ + public function pttl() -> int + { + return this->getAdapter()->pttl(key); + } + /** * Flushes/clears the cache * From 0e8445f7acd831bf403a5164a8bf4401f1e9eebf Mon Sep 17 00:00:00 2001 From: Zike Date: Tue, 27 Dec 2022 08:20:03 -0500 Subject: [PATCH 2/3] Update phalcon/Storage/Adapter/Redis.zep Co-authored-by: Anton Vasiliev --- phalcon/Storage/Adapter/Redis.zep | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phalcon/Storage/Adapter/Redis.zep b/phalcon/Storage/Adapter/Redis.zep index bf40d9ee6ae..b056d95a393 100644 --- a/phalcon/Storage/Adapter/Redis.zep +++ b/phalcon/Storage/Adapter/Redis.zep @@ -71,8 +71,7 @@ class Redis extends AbstractAdapter /** * Returns the time to live left for a given key in seconds * - * @param string $key - * LONG: The time to live in seconds. If the key has no ttl, -1 will be returned, and -2 if the key doesn't exist. + * @param string $key LONG: The time to live in seconds. If the key has no ttl, -1 will be returned, and -2 if the key doesn't exist. * @return int * @throws StorageException */ From f6157ddd7c0a7a261a4554865b8051ccca043e26 Mon Sep 17 00:00:00 2001 From: Zike Date: Tue, 27 Dec 2022 08:44:37 -0500 Subject: [PATCH 3/3] update Storage/Adapter/Redis.zep add function to return the time to live left for a given key in seconds (ttl), or milliseconds (pttl). --- phalcon/Storage/Adapter/Redis.zep | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/phalcon/Storage/Adapter/Redis.zep b/phalcon/Storage/Adapter/Redis.zep index b056d95a393..f526a0978ca 100644 --- a/phalcon/Storage/Adapter/Redis.zep +++ b/phalcon/Storage/Adapter/Redis.zep @@ -69,13 +69,15 @@ class Redis extends AbstractAdapter } /** - * Returns the time to live left for a given key in seconds + * Returns the time to live left for a given key in seconds. + * If the key has no ttl, -1 will be returned, and -2 if the key doesn't exist. + * + * @param string $key * - * @param string $key LONG: The time to live in seconds. If the key has no ttl, -1 will be returned, and -2 if the key doesn't exist. * @return int * @throws StorageException */ - public function ttl($key) -> int + public function ttl(string! key) -> int { return this->getAdapter()->ttl(key); } @@ -88,7 +90,7 @@ class Redis extends AbstractAdapter * @return int * @throws StorageException */ - public function pttl() -> int + public function pttl(string! key) -> int { return this->getAdapter()->pttl(key); }