public <HK, HV> HashOperations<K, HK, HV> opsForHash() { return new DefaultHashOperations(this);
}每次用opsForHash()都会新生成一个DefaultHashOperations如果一个RedisUtil里只生成一个DefaultHashOperations, 每次都调用这一个,有何问题?DefaultHashOperations,DefaultSetOperations等是线程安全的吗?@Componentpublic final class RedisUtil { private HashOperations<String, Object, Object> hashOperations;
@Autowired
private RedisTemplate<String, Object> redisTemplate; @PostConstruct
void init(){
hashOperations = redisTemplate.opsForHash();
} public Set<Object> allFields(String key) { return redisTemplate.opsForHash().keys(key);
} public List<Object> allValues(String key) { return redisTemplate.opsForHash().values(key);
}
}
添加回答
举报
0/150
提交
取消