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.stereotype.Component;

import java.util.Set;

@Component
public class OnlineDataCache {
    @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();
    }

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

    public void remove(Long roomId) {
        RSet<String> set = redissonClient.getSet(getKey());
        set.remove(roomId+"");
    }
}
