gpt4 book ai didi

java - Spring Cache 中的@Cacheable 在缓存外的redis 中存储值。我如何将它放入redis的缓存中?

转载 作者:可可西里 更新时间:2023-11-01 11:23:54 25 4
gpt4 key购买 nike

@Override
@Cacheable("stu")
public EmployeeEntity getEmployee(Integer id) {

return employeeDAO.findById(id).get();
}

以上代码将 key 以“stu::7”格式保存在redis中这里“stu”是缓存的名称,7 是键,但它将缓存名称和 id 作为一个键存储。

但我想以这种格式存储在 redis STU ->7Stu 应该是缓存的名称,里面是所有的键值对。

最佳答案

您可以将自定义 key 生成器设置为 @Cacheable 注释,您可以根据需要对其进行自定义:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html#keyGenerator--

@Cacheable(value = "stu", keyGenerator = "customKeyGenerator")

其中 customKeyGenerator 是您的自定义 key 生成器 bean 的名称。

关于java - Spring Cache 中的@Cacheable 在缓存外的redis 中存储值。我如何将它放入redis的缓存中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54420829/

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