cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Update Redis.zep

Open zikezhang opened this issue 2 years ago • 4 comments

add ttl() and pttl() to that developer can get Redis TTL.

Hello!

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 avatar Dec 26 '22 20:12 zikezhang

@zikezhang Could you please add some basic tests for theses methods?

Jeckerson avatar Dec 26 '22 22:12 Jeckerson

@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 avatar Dec 27 '22 13:12 zikezhang

@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.

niden avatar Dec 27 '22 16:12 niden

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.

rudiservo avatar Sep 11 '23 18:09 rudiservo