fix: RedisCache flush with prefix#8148
Conversation
|
I noticed that This probably won’t cause any real issue in normal Kirby usage, but if the same Redis connection is later used for scan(), its behavior would stay changed. To avoid that side effect, would it make sense to store the old Something like: $scan = $this->connection->getOption(Redis::OPT_SCAN);
try {
...
} finally {
$this->connection->setOption(Redis::OPT_PREFIX, $prefix);
$this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
$this->connection->setOption(Redis::OPT_SCAN, $scan);
} |
|
@afbora $this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
$this->connection->setOption(Redis::OPT_SCAN, $scan); |
|
@distantnative I tested my first idea again and I think it was not fully correct. First I thought this would be enough: $this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
$this->connection->setOption(Redis::OPT_SCAN, $scan);But $this->connection->setOption(Redis::OPT_SCAN, 3);PhpRedis can understand that as $this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
$this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NOPREFIX);
if (($scan & Redis::SCAN_RETRY) !== 0) {
$this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);
}
if (($scan & Redis::SCAN_PREFIX) !== 0) {
$this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_PREFIX);
}So basically:
But I think it needs more tests. |
|
@afbora Maybe I do not understand the Redis behavior here: $this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);
$this->connection->setOption(Redis::OPT_SCAN, Redis::SCAN_NOPREFIX);But it reads like we first set the |
|
@distantnative I tested this with a small script and it seems Output: $ php scripts/redis-scan-option-debug.php
Constants:
SCAN_NORETRY = 0
SCAN_RETRY = 1
SCAN_PREFIX = 2
SCAN_NOPREFIX = 3
Initial value=0 retry=off prefix=off
After SCAN_RETRY value=1 retry=on prefix=off
After SCAN_PREFIX value=3 retry=on prefix=on
Now disable only retry:
After SCAN_NORETRY value=2 retry=off prefix=on
Now disable only prefix:
After SCAN_NOPREFIX value=0 retry=off prefix=off
Reset and restore a combined old value:
After full reset value=0 retry=off prefix=off
After restoring old value value=3 retry=on prefix=onSo Here the script: redis-scan-option-debug.php |
Changelog
🐛 Bug fixes
For review team