package com.sonic.lion.utils;

import com.sonic.common.AppRuntime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 统一的 redis key 管理工具类（方便后续的维护和查找）
 *
 * @Author code
 * @Date 2021/9/24
 * @Version 1.0
 */
@Slf4j
@Service
public class RedisKeyUtils {

    @Autowired
    private AppRuntime appRuntime;

    /**
     * 下单总数限制
     *
     * @return
     */
    public String createPrePayTrade(Long userId) {
        return appRuntime.buildPrefixKey("lock", "createPrePayTradeV1", userId);
    }

    /**
     * 提现锁
     * @param userId
     * @return
     */
    public String withdrawLockKey(Long userId) {
        return appRuntime.buildPrefixKey("lock", "withdraw", userId);
    }

    /**
     * 订阅会话缓存
     * @param userId
     * @return
     */
    public String subSessionIdCacheKey(Long userId) {
        return appRuntime.buildPrefixKey("sub", "sessionId", userId);
    }

}
