0

I'm running an application on AWS Elastic Beanstalk PHP 7.3 running on 64bit Amazon Linux/2.9.12 and I've recently starting getting the following error -

Call to undefined method Redis::delete()

I have a Redis cache configuration which I'm able to write to and read. But then when I try to delete the same, I get the above error. This was not happening before. I have correctly configured the cache like below

Cache::config('1min', [
'engine' => CACHE_ENGINE,
'server' => CACHE_HOST,
'port' => CACHE_PORT,
'prefix' => CACHE_PREFIX,
'duration'=>'+1 minute'
]);

And I'm able to execute the following actions

Cache::write('cache1', 'value', '1min');
Cache::read('cache1', '1min');

without any errors. It's only when I try to delete the key using the following command

Cache::delete('cache1', '1min');

that I'm getting the above error.

I'm using phpredis which I install via .ebextensions. I'm downloading the package via this link -

https://github.com/phpredis/phpredis/archive/develop.zip -O phpredis.zip

Upon doing some research, I found that the delete function in Redis.php is deprecated as is soon going to be deleted. When I change the function call in the RedisEngine.php file (this is a CakePHP library file which gets downloaded as a dependency via composer) on line 176 from

public function delete($key) {
    return $this->_Redis->delete($key) > 0;
}

to

public function delete($key) {
    return $this->_Redis->del($key) > 0;
}

the Cache delete works correctly. This was not happening before. If I can get some assistance with this at the earliest that would be much appreciated.

Thank you!

Prathamesh Datar
  • 375
  • 1
  • 4
  • 20

1 Answers1

0

In documentation of phpredis is written as note:

Note: delete is an alias for del and will be removed in future versions of phpredis.

Consider using unlink instead of delete and del methods because unlink is working asynchronously and this will not block your code execution.

Note that unlink is available only if your redis version is equal to or bigger than 4.0.0

GTsvetanov
  • 1,250
  • 6
  • 16
  • Hello @GTsvetanov - Thank you for your answer. I also realised the above when I went through the documentation for PHPRedis but the actual function call of 'delete' is happening from a CakePHP library file - RedisEngine.php which I download via composer. So I think this is an update that will need to be done on the CakePHP composer download? – Prathamesh Datar Jan 21 '21 at 07:00
  • Hello @PrathameshDatar I've made a quick check and it this is truth - https://discourse.cakephp.org/t/how-long-will-cakephp-2-x-be-supported/3880 then 2.x is no more maintained except for security fixes because 4.0 release date is in December-2019 so if you won't update you packages via composer you can directly fix the issue in vendor package (it not a good practice!). Other way is to create a PR in their git with request to fix the issue in new version of 2.x. – GTsvetanov Jan 21 '21 at 17:06