Closed shushenghong closed 4 years ago
@shushenghong is there any safer approach?
i suggest use scan command with keyPrefix, and set default keyPrefix like redis session.
loop
scan cursor match keyPrefix* count 100
del key1 key2 ...
How would that work with thousands of keys?
another suggestion, if we use redis hashes to store cache, one hash store no more than 200 fields e.g., so we can avoid this problem?
That would require changing the way cache is stored significantly. I'm not sure about performance of such solution compared to current one.
This is a serious issue, and deserves at least a huge red bold warning in the documentation while not fixed. In our case, we do not use any app data in Redis, but we do use the extension to store cache entries and session and mutexes. Needless to say, wiping out the latter have huge implications.
BTW, a workaround we're using here is to use a Redis "database" only for cache components. That way, flushing caches doesn't affect sessions and mutexes.
if use redis as cache, yii cache/flush-all is very dangerous, since it will flushdb, if there are other data inside the same redis db, they all be cleared.