Is there any way to get the expiry time of a Redis cache?
$cache_name = "category_15";
$cache_value = cache()->get($cache_name);
// is there any way to find ttl/pttl value? I tested the below one.
$cache_expire_time = Redis::ttl($cache_name); // always returns '-2'.
Laravel Cache will prefix the key using the value provided in /config/cache.php.
So, when using Redis facade directly you will have to include the prefix manually. Something like this:
Redis::ttl(config('cache.prefix') . $cache_name);
// there is also pttl function.
// It may return -2 if the key doesn't exist, or -1 if the key has no expiration set.