1 Ağustos 2021 Pazar

SpringData Redis SetOperations 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 Set
  public void addToSet(String key, T... values) {
    setOperations.add(key, values);
  }

  public Set<T> getSetMembers(String key) {
    return setOperations.members(key);
  }
  //endregion

}

Hiç yorum yok:

Yorum Gönder