Şöyle yaparız
@Componentpublic class RedisUtil<T> {private RedisTemplate<String, T> redisTemplate;private ValueOperations<String, T> valueOperations;private ListOperations<String, T> listOperations;private SetOperations<String, T> setOperations;private HashOperations<String, Integer, T> hashOperations;@Autowiredpublic RedisUtil(RedisTemplate<String, T> redisTemplate) {this.redisTemplate = redisTemplate;this.valueOperations = redisTemplate.opsForValue();this.listOperations = redisTemplate.opsForList();this.setOperations = redisTemplate.opsForSet();this.hashOperations = redisTemplate.opsForHash();}//region Listpublic void addList(String key, T value) {listOperations.leftPush(key, value);}public List<T> getListMembers(String key) {return listOperations.range(key, 0, -1);}public Long getListSize(String key) {return listOperations.size(key);}//endregion}
Hiç yorum yok:
Yorum Gönder