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

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

上面的代码将密钥以这种格式保存在redis中“stu::7”
这里“stu”是缓存的名称,7是密钥,但它将缓存名称和id存储为一个密钥。
但我想以这种格式存储在redis stu->7中
stu应该是缓存的名称,其中包含所有的键值对。

最佳答案

您可以将自定义密钥生成器设置为@Cacheable批注,在这里您可以根据需要自定义它:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/annotation/Cacheable.html#keyGenerator--

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

其中customKeyGenerator是自定义密钥生成器bean的名称。

08-03 16:48