public <HK, HV> HashOperations<K, HK, HV> opsForHash() {
return new DefaultHashOperations(this);
}
A new DefaultHashOperations is generated every time I use opsForHash ()
if only one DefaultHashOperations is generated in a RedisUtil and this one is called every time, what"s the problem? Are
DefaultHashOperations,DefaultSetOperations and so on thread safe?
@Component
public 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);
}
}