Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
469 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...