Redis SCAN 文档中有这样一条注释:
The SCAN algorithm is guaranteed to terminate only if the size of the iterated collection remains bounded to a given maximum size, otherwise iterating a collection that always grows may result into SCAN to never terminate a full iteration.
在 Redis 用于存储 session 的场景中(因此可以不断扩展),发生这种情况的可能性有多大?在生产中使用 SCAN 进行完整迭代是否安全(例如清除一组具有给定前缀的键)?
最佳答案
为防止扫描迭代花费太长时间,您可以在开始扫描之前获取键空间大小,并在扫描了那么多键后终止扫描。
关于redis - Redis SCAN 永不终止的可能性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55071977/