package cn.qinys.platform.gateway.utils;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


import java.util.concurrent.TimeUnit;

/**
 * Description:
 *
 * @author tanlie
 * Date: 2024/1/9 9:08
 */
@Component
public class RedisUtils {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 分布式锁过期时间
     */
    private final long EXPIRE_TIME = 5 * 10000;

    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void set(String key, Object obj) {
        redisTemplate.opsForValue().set(key, obj);
    }

    public void set(String key, Object obj, long expire) {
        redisTemplate.opsForValue().set(key, obj, expire, TimeUnit.SECONDS);
    }

    public Boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }

}
