Skip to content

Commit 4775523

Browse files
committed
respect ttl
1 parent 5591e58 commit 4775523

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

includes/object-cache.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,13 @@ public function increment( $key, $offset = 1, $group = 'default' ) {
23542354
if ( $this->use_igbinary ) {
23552355
$value = (int) $this->parse_redis_response( $this->maybe_unserialize( $this->redis->get( $derived_key ) ) );
23562356
$value += $offset;
2357-
$result = $this->parse_redis_response( $this->redis->set( $derived_key, $this->maybe_serialize( $value ) ) );
2357+
$serialized = $this->maybe_serialize( $value );
2358+
2359+
if ( $pttl = $this->redis->pttl( $derived_key ) ) {
2360+
$result = $this->parse_redis_response( $this->redis->set( $derived_key, $serialized, [ 'px' => $pttl ] ) );
2361+
} else {
2362+
$result = $this->parse_redis_response( $this->redis->set( $derived_key, $serialized ) );
2363+
}
23582364

23592365
if ( $result ) {
23602366
$this->add_to_internal_cache( $derived_key, $value );
@@ -2421,7 +2427,13 @@ public function decrement( $key, $offset = 1, $group = 'default' ) {
24212427
if ( $this->use_igbinary ) {
24222428
$value = (int) $this->parse_redis_response( $this->maybe_unserialize( $this->redis->get( $derived_key ) ) );
24232429
$value -= $offset;
2424-
$result = $this->parse_redis_response( $this->redis->set( $derived_key, $this->maybe_serialize( $value ) ) );
2430+
$serialized = $this->maybe_serialize( $value );
2431+
2432+
if ( $pttl = $this->redis->pttl( $derived_key ) ) {
2433+
$result = $this->parse_redis_response( $this->redis->set( $derived_key, $serialized, [ 'px' => $pttl ] ) );
2434+
} else {
2435+
$result = $this->parse_redis_response( $this->redis->set( $derived_key, $serialized ) );
2436+
}
24252437

24262438
if ( $result ) {
24272439
$this->add_to_internal_cache( $derived_key, $value );

0 commit comments

Comments
 (0)