myol February 2016

Laravel cache remaining TTL

I am looking for a way to access the remaining TTL of a redis key value pair via laravel. I don't mind using either the Cache or Redis facades (or anything else for that matter).

In the api I can only see how to return the default TTL - getDefaultCacheTime().

I want to find the remaining TTL.

For reference, the redis terminal command is TTL mykey

Answers


shempignon February 2016

Since there's a command method on the Illuminate\Redis\Database class you can simply run :

Redis::command('TTL', ['yourKey']);

This is documented here.


myol February 2016

Turns out (with the recent versions of laravel anyway) that you can use redis commands and they will be converted using magic methods. So you can simply use

Redis::ttl('yourKey');

Post Status

Asked in February 2016
Viewed 1,484 times
Voted 7
Answered 2 times

Search




Leave an answer