package com.ruoyi.sensitive.cache;

import com.ruoyi.sensitive.dto.SensitiveConfig;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SensitiveWordConfigCache {
    @Autowired
    private RedissonClient redissonClient;
    private String getKey(){
        return "sensitive-config";
    }

    public void setConfig(SensitiveConfig config){
        String key = getKey();
        RBucket<SensitiveConfig> bucket = redissonClient.getBucket(key);
        bucket.set(config);
    }

    public SensitiveConfig getConfig(){
        String key = getKey();
        RBucket<SensitiveConfig> bucket = redissonClient.getBucket(key);
        return bucket.get();
    }
}
