Closed MaximilianKresse closed 1 year ago
The redis and predis implementation of Driver::driverClear() method is currently incorrect when using the optPrefix setting. The current implementations just always call $this->instance->flushDB(); (redis and predis). This method is not effected by the prefix option and will simply wipe the current database clear.
Unfortunately it's a known limitation of Redis/Predis with Flushdb, I can't really do something about it because of the reason below:
if ($this->getConfig()->getOptPrefix() !== '') {
return (bool) $this->instance->del(...$this->instance->keys('*'));
}
return $this->instance->flushDB();
This code is a bit dangerous and not optimized because if the cache contains a lot of keys Phpfastcache will have a timeout/memory issue for sure. Retrieving all the keys from a cache is a red line that I always refused to do on Phpfastcache for performances reasons.
Mhh ok I understand your point and also don't see any reliable way to do this without the risk of a memory issue. This behaviour should be documented as it may be unexpected. For now we'll try to use our own driver.
You can also create a new database to deal with the optPrefix issue too !
Here is the documentation to help you to create then register a new driver:
You can extends the 3 classes and just override DriverClear() :)
What type of issue is this?
Incorrect/unexpected/unexplainable behavior
Connector/Database version (if applicable)
Redis and Predis
Phpfastcache version
9.1.2 ✅
Describe the issue you're facing
The redis and predis implementation of Driver::driverClear() method is currently incorrect when using the optPrefix setting. The current implementations just always call
$this->instance->flushDB();
(redis and predis). This method is not effected by the prefix option and will simply wipe the current database clear.Expected behavior
Driver::driverClear() should only clear the keys with the configured prefix.
Suggestion to fix the issue (optional)
The fixed driverClear method should look something like this:
Have you searched in our Wiki before posting ?