@@ -27,7 +27,6 @@ use std::hash::{Hash, Hasher};
27
27
use std:: io:: Cursor ;
28
28
use std:: sync:: Arc ;
29
29
use std:: sync:: Mutex ;
30
- use std:: time:: SystemTime ;
31
30
32
31
use byteorder:: { ByteOrder , NetworkEndian } ;
33
32
use ripemd160:: digest:: Digest ;
@@ -67,7 +66,6 @@ pub type AsResult<T = ()> = std::result::Result<T, AerospikeException>;
67
66
68
67
const VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
69
68
const PARTITIONS : u16 = 4096 ;
70
- const CITRUSLEAF_EPOCH : u64 = 1262304000 ;
71
69
72
70
////////////////////////////////////////////////////////////////////////////////////////////
73
71
//
@@ -1602,7 +1600,7 @@ const NEVER_EXPIRE: u32 = 0xFFFF_FFFF; // -1 as i32
1602
1600
const DONT_UPDATE : u32 = 0xFFFF_FFFE ;
1603
1601
1604
1602
/// Record expiration, also known as time-to-live (TTL).
1605
- #[ derive( Debug , Clone , Copy ) ]
1603
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
1606
1604
pub enum _Expiration {
1607
1605
Seconds ( u32 ) ,
1608
1606
NamespaceDefault ,
@@ -1628,41 +1626,73 @@ impl FromZval<'_> for Expiration {
1628
1626
#[ php_impl]
1629
1627
#[ derive( ZvalConvert ) ]
1630
1628
impl Expiration {
1631
- /// Set the record to expire X seconds from now
1629
+ /// Set the record to expire X seconds from now. See also `getTtl()`.
1632
1630
pub fn Seconds ( seconds : u32 ) -> Self {
1633
1631
Expiration {
1634
1632
_as : _Expiration:: Seconds ( seconds) ,
1635
1633
}
1636
1634
}
1637
1635
1638
- /// Set the record's expiry time using the default time-to-live (TTL) value for the namespace
1636
+ /// Answers with the expiration's current time to live in units of
1637
+ /// seconds, excluding any special values. If the expiration is set to
1638
+ /// the namespace default, is configured to never update, or is configured
1639
+ /// to never expire, this method returns null. See also `Seconds()`.
1640
+ #[ getter]
1641
+ pub fn get_ttl ( & self ) -> Option < u32 > {
1642
+ match self . _as {
1643
+ _Expiration:: Seconds ( secs) => Some ( secs) ,
1644
+ _ => None ,
1645
+ }
1646
+ }
1647
+
1648
+ /// Set the record's expiry time using the default time-to-live (TTL) value
1649
+ /// for the namespace. See also `isNamespaceDefault()`.
1639
1650
pub fn Namespace_Default ( ) -> Self {
1640
1651
Expiration {
1641
1652
_as : _Expiration:: NamespaceDefault ,
1642
1653
}
1643
1654
}
1644
1655
1656
+ /// Answers true only if the expiration is set to use the namespace default.
1657
+ /// See also `NamespaceDefault()`.
1658
+ #[ getter]
1659
+ pub fn is_namespace_default ( & self ) -> bool {
1660
+ self . _as == _Expiration:: NamespaceDefault
1661
+ }
1662
+
1645
1663
/// Set the record to never expire. Requires Aerospike 2 server version 2.7.2 or later or
1646
1664
/// Aerospike 3 server version 3.1.4 or later. Do not use with older servers.
1665
+ /// See also `willNeverExpire()`.
1647
1666
pub fn Never ( ) -> Self {
1648
1667
Expiration {
1649
1668
_as : _Expiration:: Never ,
1650
1669
}
1651
1670
}
1652
1671
1653
- /// Do not change the record's expiry time when updating the record; requires Aerospike server
1654
- /// version 3.10.1 or later.
1672
+ /// Answers true only if the expiration is set to never expire.
1673
+ /// See also `Never()`.
1674
+ pub fn will_never_expire ( & self ) -> bool {
1675
+ self . _as == _Expiration:: Never
1676
+ }
1677
+
1678
+ /// Do not change the record's expiry time when updating the record;
1679
+ /// requires Aerospike server version 3.10.1 or later.
1680
+ /// See also `willUpdateExpiration()`.
1655
1681
pub fn Dont_Update ( ) -> Self {
1656
1682
Expiration {
1657
1683
_as : _Expiration:: DontUpdate ,
1658
1684
}
1659
1685
}
1660
1686
1661
- /// Answers with the expiration's configured value in units of seconds.
1662
- #[ getter]
1663
- pub fn in_seconds ( & self ) -> u32 {
1664
- self . into ( )
1665
- }
1687
+ /// Answers *true* if the expiration is configured to somehow change during
1688
+ /// a record update. This can be as simple as an explicit time-to-live, or
1689
+ /// an instruction to use the namespace's default expiration, etc. Answers
1690
+ /// *false* if the expiration will *not* be changed during a record update
1691
+ /// (e.g., the expiration was constructed with DontUpdate().)
1692
+ #[ getter]
1693
+ pub fn will_update_expiration ( & self ) -> bool {
1694
+ self . _as != _Expiration:: DontUpdate
1695
+ }
1666
1696
}
1667
1697
1668
1698
impl From < & Expiration > for u32 {
@@ -4217,8 +4247,9 @@ impl Record {
4217
4247
Some ( self . _as . generation )
4218
4248
}
4219
4249
4220
- /// Expiration is TTL (Time-To-Live).
4221
- /// Number of seconds until record expires.
4250
+ /// Expiration indicates when a record will expire (Time-To-Live).
4251
+ /// To determine a record's time to live, use the `getTtl()` method on the
4252
+ /// Expiration or, equivalently, on the record.
4222
4253
#[ getter]
4223
4254
pub fn get_expiration ( & self ) -> Expiration {
4224
4255
match self . _as . expiration {
@@ -4227,28 +4258,12 @@ impl Record {
4227
4258
}
4228
4259
}
4229
4260
4230
- /// Expiration is TTL (Time-To-Live).
4231
- /// Number of seconds until record expires.
4261
+ /// Answer with the record's TTL (Time-To-Live), or null if not
4262
+ /// possible. Expressed in number of seconds until record expires.
4263
+ /// Equivalent to `$this->getExpiration()->getTtl()`.
4232
4264
#[ getter]
4233
4265
pub fn get_ttl ( & self ) -> Option < u32 > {
4234
- match self . _as . expiration {
4235
- 0 => NEVER_EXPIRE . into ( ) ,
4236
- secs => {
4237
- let expiration = CITRUSLEAF_EPOCH + ( secs as u64 ) ;
4238
- let now = SystemTime :: now ( )
4239
- . duration_since ( SystemTime :: UNIX_EPOCH )
4240
- . unwrap ( )
4241
- . as_secs ( ) ;
4242
-
4243
- // Record may not have expired on server, but delay or clock differences may
4244
- // cause it to look expired on client. Floor at 1, not 0, to avoid old
4245
- // "never expires" interpretation.
4246
- if expiration > now {
4247
- return ( ( ( expiration as u64 ) - now) as u32 ) . into ( ) ;
4248
- }
4249
- return ( 1 as u32 ) . into ( ) ;
4250
- }
4251
- }
4266
+ self . get_expiration ( ) . get_ttl ( )
4252
4267
}
4253
4268
4254
4269
/// Key is the record's key.
@@ -9750,7 +9765,6 @@ impl Client {
9750
9765
/// Write record bin(s). The policy specifies the transaction timeout, record expiration and
9751
9766
/// how the transaction is handled when the record already exists.
9752
9767
pub fn put ( & self , policy : & WritePolicy , key : & Key , bins : Vec < & Bin > ) -> PhpResult < ( ) > {
9753
- eprintln ! ( "LBPUT001 put() entered" ) ;
9754
9768
let bins: Vec < proto:: Bin > = bins. into_iter ( ) . map ( |b| b. into ( ) ) . collect ( ) ;
9755
9769
9756
9770
let request = tonic:: Request :: new ( proto:: AerospikePutRequest {
@@ -9768,7 +9782,6 @@ impl Client {
9768
9782
} => Ok ( ( ) ) ,
9769
9783
pe => {
9770
9784
let error: AerospikeException = pe. into ( ) ;
9771
- eprintln ! ( "LBPUT002 Error detected: {:?}" , error) ;
9772
9785
throw_object ( error. into_zval ( true ) ?) ?;
9773
9786
Ok ( ( ) )
9774
9787
}
0 commit comments