Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions php_stubs/libaerospike-php-stubsv1.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
26 changes: 6 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,7 +66,6 @@ pub type AsResult<T = ()> = std::result::Result<T, AerospikeException>;

const VERSION: &str = env!("CARGO_PKG_VERSION");
const PARTITIONS: u16 = 4096;
const CITRUSLEAF_EPOCH: u64 = 1262304000;

////////////////////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -4216,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),
}
}

Expand All @@ -4226,22 +4226,8 @@ impl Record {
#[getter]
pub fn get_ttl(&self) -> Option<u32> {
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();
}
NEVER_EXPIRE => None,
secs => (secs as u32).into(),
}
}

Expand Down