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); } }
手掌心
守候你守候我
相关分类