Update Redis.zep
add ttl() and pttl() to that developer can get Redis TTL.
Hello!
- Type: new feature
- Link to issue: https://github.com/phpredis/phpredis#ttl-pttl
In raising this pull request, I confirm the following:
- [x] I have read and understood the Contributing Guidelines
- [x] I have checked that another pull request for this purpose does not exist
- [ ] I wrote some tests for this PR
Small description of change: add ttl(), pttl() for Redis. Thanks
@zikezhang Could you please add some basic tests for theses methods?
@zikezhang Could you please add some basic tests for theses methods?
Hi @Jeckerson, yes, I will. I am sorry for the inconvenience. So, one of my project, I need to implement a throttle middleware by updating the value in Redis without changing the TTL. I have to code it like this:
$ttl = $hits ? $cache->getAdapter()->getAdapter()->ttl($key)
: $minutes * 60;
As you can see. I have to call getAdapter() twice to invoke it.
We might add a similar function on each Adapter and then we can get the TTL by $cache->ttl($key)
@zikezhang Could you please add some basic tests for theses methods?
Hi @Jeckerson, yes, I will. I am sorry for the inconvenience. So, one of my project, I need to implement a throttle middleware by updating the value in Redis without changing the TTL. I have to code it like this:
$ttl = $hits ? $cache->getAdapter()->getAdapter()->ttl($key) : $minutes * 60;As you can see. I have to call
getAdapter()twice to invoke it. We might add a similar function on each Adapter and then we can get the TTL by$cache->ttl($key)
Adding this to the Cache layer will alter the interface and we will need to add all these methods to the adapters and relevant interface also
We need to explore what the other adapters offer in terms of TTL so as to promote it to the adapter. Also the Cache adapters rely on the Storage namespace so all changes have to happen there first.
apcu has this on https://www.php.net/manual/en/function.apcu-key-info.php
Memcached has something called MetaCommands, unfortunately php-memcached is heavily reliant on libmemcached that is a bit behind. Already submitted an issue on lauchpad on the libmemcached project.
There is a project https://github.com/awesomized/libmemcached that is trying to implement the meta protocol for the past 3 years.