gpt4 book ai didi

spring-boot - 为什么Spring-data-redis在缓存驱逐时使用keys命令

转载 作者:行者123 更新时间:2023-12-04 13:35:29 24 4
gpt4 key购买 nike

当我使用 springboot 时,我使用 redis 作为我的缓存服务器。
但是我看了spring-data-redis的源码,当evict cache的时候,代码是

byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet())
.toArray(new byte[0][]);

Redis 建议将 keys 命令替换为 scan 命令。为什么Spring团队不这样做。

最佳答案

此功能在当前发布的版本 ( 2.5.5 ) 中不可用,并且更有可能包含在下一个版本 ( 2.6.* ) 中

The cache implementation defaults to use KEYS and DEL to clear thecache. KEYS can cause performance issues with large keyspaces.Therefore, the default RedisCacheWriter can be created with aBatchStrategy to switch to a SCAN-based batch strategy. The SCANstrategy requires a batch size to avoid excessive Redis commandroundtrips:

RedisCacheManager cm = RedisCacheManager.build(RedisCacheWriter.nonLockingRedisCacheWriter(
connectionFactory,
BatchStrategies.scan(1000))
).cacheDefaults(defaultCacheConfig())

Note: The KEYS batch strategy is fully supported using any driver andRedis operation mode (Standalone, Clustered). SCAN is fully supportedwhen using the Lettuce driver. Jedis supports SCAN only innon-clustered modes.


https://github.com/spring-projects/spring-data-redis/blob/main/src/main/asciidoc/reference/redis-cache.adoc

关于spring-boot - 为什么Spring-data-redis在缓存驱逐时使用keys命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62340863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com