From 711275e0260201a1e85d2bf6c7ef2187c7c80ce3 Mon Sep 17 00:00:00 2001 From: Asparuh Nestorov Date: Thu, 24 Jul 2025 12:02:49 +0300 Subject: [PATCH 1/4] Fixing TTL value in get_ttl --- src/lib.rs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 044bdf8..b666d0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,6 @@ use std::hash::{Hash, Hasher}; use std::io::Cursor; use std::sync::Arc; use std::sync::Mutex; -use std::time::SystemTime; use byteorder::{ByteOrder, NetworkEndian}; use ripemd160::digest::Digest; @@ -67,7 +66,6 @@ pub type AsResult = std::result::Result; const VERSION: &str = env!("CARGO_PKG_VERSION"); const PARTITIONS: u16 = 4096; -const CITRUSLEAF_EPOCH: u64 = 1262304000; //////////////////////////////////////////////////////////////////////////////////////////// // @@ -4224,24 +4222,10 @@ impl Record { /// Expiration is TTL (Time-To-Live). /// Number of seconds until record expires. #[getter] - pub fn get_ttl(&self) -> Option { + pub fn get_ttl(&self) -> Option { match self._as.expiration { - 0 => NEVER_EXPIRE.into(), - secs => { - let expiration = CITRUSLEAF_EPOCH + (secs as u64); - let now = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - - // Record may not have expired on server, but delay or clock differences may - // cause it to look expired on client. Floor at 1, not 0, to avoid old - // "never expires" interpretation. - if expiration > now { - return (((expiration as u64) - now) as u32).into(); - } - return (1 as u32).into(); - } + 0 => (NEVER_EXPIRE as i32).into(), + secs => (secs as i32).into(), } } From 5473e7feb005963288a6ddfbdf6dd677706c2817 Mon Sep 17 00:00:00 2001 From: Asparuh Nestorov Date: Thu, 24 Jul 2025 17:45:50 +0300 Subject: [PATCH 2/4] getExpiration fix --- src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b666d0c..a465586 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4214,8 +4214,10 @@ impl Record { #[getter] pub fn get_expiration(&self) -> Expiration { match self._as.expiration { - 0 => NEVER_EXPIRE.into(), - secs => secs.into(), + NAMESPACE_DEFAULT => Expiration::Namespace_Default(), + NEVER_EXPIRE => Expiration::Never(), + DONT_UPDATE => Expiration::Dont_Update(), + secs => Expiration::Seconds(secs), } } From a3d710859bb0537ddf3753d85b8e3fefbcdaeb2a Mon Sep 17 00:00:00 2001 From: Asparuh Nestorov Date: Thu, 24 Jul 2025 18:02:31 +0300 Subject: [PATCH 3/4] Never Expire should be Constant --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a465586..0b5aef0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4226,7 +4226,7 @@ impl Record { #[getter] pub fn get_ttl(&self) -> Option { match self._as.expiration { - 0 => (NEVER_EXPIRE as i32).into(), + NEVER_EXPIRE => (NEVER_EXPIRE as i32).into(), secs => (secs as i32).into(), } } From c64937f3a556df064af7a12085fa8ec575223e7b Mon Sep 17 00:00:00 2001 From: Asparuh Nestorov Date: Thu, 24 Jul 2025 18:53:31 +0300 Subject: [PATCH 4/4] Getting TTL as u32 and NULL if Never Expire --- php_stubs/libaerospike-php-stubsv1.0.0.php | 1 + src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/php_stubs/libaerospike-php-stubsv1.0.0.php b/php_stubs/libaerospike-php-stubsv1.0.0.php index e2b0d76..5f66e0e 100644 --- a/php_stubs/libaerospike-php-stubsv1.0.0.php +++ b/php_stubs/libaerospike-php-stubsv1.0.0.php @@ -4278,6 +4278,7 @@ public function getExpiration(): \Aerospike\Expiration {} /** * Expiration is TTL (Time-To-Live). * Number of seconds until record expires. + * Returns NULL if TTL is set to Never Expire. */ public function getTtl(): ?int {} diff --git a/src/lib.rs b/src/lib.rs index 0b5aef0..55e47b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4224,10 +4224,10 @@ impl Record { /// Expiration is TTL (Time-To-Live). /// Number of seconds until record expires. #[getter] - pub fn get_ttl(&self) -> Option { + pub fn get_ttl(&self) -> Option { match self._as.expiration { - NEVER_EXPIRE => (NEVER_EXPIRE as i32).into(), - secs => (secs as i32).into(), + NEVER_EXPIRE => None, + secs => (secs as u32).into(), } }