1 Ağustos 2021 Pazar

SpringData Redis ListOperations Sınıfı

Örnek
Şöyle yaparız
@Component
public 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;

  @Autowired
  public 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 List
  public 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