package com.liquidnet.common.cache.redis.util;

import com.liquidnet.common.cache.redis.config.AbstractRedisConfig;
import com.liquidnet.common.cache.redis.config.RedisDragonConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author AnJiabin <jiabin.an@lightnet.io>
 * @version V1.0
 * @Description: Redis工具类
 * @class: RedisUtil
 * @Package com.liquidnet.stellar.utils
 * @Copyright: LightNet @ Copyright (c) 2020
 * @date 2020/8/26 13:11
 */
@Slf4j
@Component("redisDragonUtil")
public final class RedisDragonUtil extends AbstractRedisUtil{
    @Autowired
    private RedisDragonConfig redisConfig;
    @Value("${spring.profiles.active:prod}")
    private String prefix;

    @Override
    public String fillingKey(String key) {
        return prefix.equals("prod") ? key : prefix.concat(":").concat(key);
    }

    @Override
    public int getDbs() {
        log.info("redisDragonUtil.totalDbs:{},prefix:{}===", redisConfig.totalDbs, prefix);
        return redisConfig.totalDbs;
    }

    @Override
    AbstractRedisConfig getRedisConfig() {
        return this.redisConfig;
    }
}
