package com.ruoyi.cai.ws.cache;

import com.ruoyi.cai.ws.constant.RedisConstant;
import org.redisson.api.RSet;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

@Component
public class OnlineDataCache {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private RedissonClient redissonClient;

    public String getKey(){
        return RedisConstant.ONLINE_ROOM_DATA;
    }

    public Set<String> getAll(){
        RSet<String> set = redissonClient.getSet(getKey());
        return set.readAll();
//        return redisTemplate.opsForSet().members(getKey());
    }

    public void add(Long roomId){
        RSet<String> set = redissonClient.getSet(getKey());
        set.add(String.valueOf(roomId));
//        redisTemplate.opsForSet().add(getKey(), String.valueOf(roomId));
    }

    public void remove(Long roomId) {
        RSet<String> set = redissonClient.getSet(getKey());
        set.delete();
//        redisTemplate.opsForSet().remove(getKey(),roomId);
    }
}
