拉拉维尔 5.2 缓存增量和过期


Laravel 5.2 Cache Increment and Expiration

那么当我设置要缓存的值并且我想递增该值时,它会重置过期时间?

为了测试它,我将值和过期时间设置为 1 分钟。然后我使用每秒递增,直到 1 分钟,它没有过期。

如何在不重置到期时间的情况下递增?

$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

如果缓存驱动程序是 Redis。代码是工作的

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

如果您使用的是"predis/predis"软件包

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