package com.sqx.common.utils;

import cn.hutool.core.date.DateUtil;

/**
 * Redis所有Keys
 *
 */
public class RedisKeys {

    public static final String FREE_WATCH_KEY = "free:watch:";
    public static final String LOCK_KEY = "SYS:LOCK:";
    public static final String RATE_LIMIT = "RATE:z";



    public static String getSysConfigKey(String key){
        return "sys:config:" + key;
    }

    public static String getDateKey(String key){
        return "date:" + key;
    }

    public static String getFreeWatchKey(Long userId, boolean isPermanently) {
        if (isPermanently) {
            return FREE_WATCH_KEY + userId;
        }
        return FREE_WATCH_KEY + DateUtil.today() + ":" + userId;
    }

    public static void main(String[] args) {
        System.out.println(DateUtil.today());
    }


    public static String getLockKey(String sign, Object... args) {
        StringBuilder key = new StringBuilder(LOCK_KEY + ":" + sign + ":");
        for (Object arg : args) {
            if (arg != null) {
                key.append(":").append(arg);
            }
        }
        return key.toString();
    }

    public static String getUserIpRateKey(long userId, String ip) {
        return RATE_LIMIT + "user:" + userId + ":ip:" + ip;
    }

    public static String getUserUrlRateKey(long userId, String url) {
        return RATE_LIMIT + "user:" + userId + ":url:" + url;
    }
}
