'Laravel 5.2 Cache Increment and Expiration

So when I set a value to be cached and I want to increment the value it resets the expiration time?

To test it I've set a value and expiration to 1 minute. Then I used increment every second until 1 minute and it didn't expire.

How can I increment without resetting the expiration time?

$app->cache->put($requestCache . '_Minute', 0, 1); // value 0, expire in 1 minute
$app->cache->increment($requestCache . '_Minute'); // doing this resets the 1 minute expire time


Solution 1:[1]

If cache driver is Redis. The code is work

$app->cache->put($key, $app->cache->increment($key), 1)

Solution 2:[2]

If you are using "predis/predis" package

  $storage=Redis::connection();
  $storage->zIncrBy("",1,$key)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 juice
Solution 2 Hassan Elshazly Eida