All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m6s
- 新增 is_standalone 物化列 + 触发器自动维护(迁移 056) - 并行查询拆分:多店铺 IN 查询拆为 per-shop goroutine 并行 Index Scan - 两阶段延迟 Join:深度分页(page≥50)走覆盖索引 Index Only Scan 取 ID 再回表 - COUNT 缓存:per-shop 并行 COUNT + Redis 30 分钟 TTL - 索引优化:删除有害全局索引、新增 partial composite indexes(迁移 057/058) - ICCID 模糊搜索路径隔离:trigram GIN 索引走独立查询路径 - 慢查询阈值从 100ms 调整为 500ms - 新增 30M 测试数据种子脚本和 benchmark 工具
288 lines
10 KiB
Go
288 lines
10 KiB
Go
package constants
|
||
|
||
import "fmt"
|
||
|
||
// ========================================
|
||
// 认证相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisAuthTokenKey 生成访问令牌的 Redis 键
|
||
// 用途:存储用户 access token 信息
|
||
// 过期时间:24 小时(可配置)
|
||
func RedisAuthTokenKey(token string) string {
|
||
return fmt.Sprintf("auth:token:%s", token)
|
||
}
|
||
|
||
// RedisRefreshTokenKey 生成刷新令牌的 Redis 键
|
||
// 用途:存储用户 refresh token 信息
|
||
// 过期时间:7 天(可配置)
|
||
func RedisRefreshTokenKey(token string) string {
|
||
return fmt.Sprintf("auth:refresh:%s", token)
|
||
}
|
||
|
||
// RedisUserTokensKey 生成用户令牌列表的 Redis 键
|
||
// 用途:维护用户的所有有效 token 列表(Set 结构)
|
||
// 过期时间:7 天(可配置)
|
||
func RedisUserTokensKey(userID uint) string {
|
||
return fmt.Sprintf("auth:user:%d:tokens", userID)
|
||
}
|
||
|
||
// RedisRateLimitKey 生成限流的 Redis 键
|
||
func RedisRateLimitKey(ip string) string {
|
||
return fmt.Sprintf("ratelimit:%s", ip)
|
||
}
|
||
|
||
// RedisTaskLockKey 生成任务锁的 Redis 键
|
||
// 用途:幂等性控制,防止重复执行
|
||
// 过期时间:24 小时
|
||
func RedisTaskLockKey(requestID string) string {
|
||
return fmt.Sprintf("task:lock:%s", requestID)
|
||
}
|
||
|
||
// RedisTaskStatusKey 生成任务状态的 Redis 键
|
||
// 用途:存储任务执行状态
|
||
// 过期时间:7 天
|
||
func RedisTaskStatusKey(taskID string) string {
|
||
return fmt.Sprintf("task:status:%s", taskID)
|
||
}
|
||
|
||
// RedisShopSubordinatesKey 生成店铺下级 ID 列表的 Redis 键
|
||
// 用途:缓存递归查询的下级店铺 ID 列表
|
||
// 过期时间:30 分钟
|
||
func RedisShopSubordinatesKey(shopID uint) string {
|
||
return fmt.Sprintf("shop:subordinates:%d", shopID)
|
||
}
|
||
|
||
// RedisVerificationCodeKey 生成验证码的 Redis 键
|
||
// 用途:存储手机验证码
|
||
// 过期时间:5 分钟
|
||
func RedisVerificationCodeKey(phone string) string {
|
||
return fmt.Sprintf("verification:code:%s", phone)
|
||
}
|
||
|
||
// RedisVerificationCodeLimitKey 生成验证码发送频率限制的 Redis 键
|
||
// 用途:限制验证码发送频率
|
||
// 过期时间:60 秒
|
||
func RedisVerificationCodeLimitKey(phone string) string {
|
||
return fmt.Sprintf("verification:limit:%s", phone)
|
||
}
|
||
|
||
// ========================================
|
||
// 钱包相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisWalletLockKey 生成钱包操作锁的 Redis 键
|
||
// 用途:钱包余额变更时的分布式锁,防止并发冲突
|
||
// 过期时间:10 秒
|
||
func RedisWalletLockKey(walletID uint) string {
|
||
return fmt.Sprintf("wallet:lock:%d", walletID)
|
||
}
|
||
|
||
// RedisWalletBalanceKey 生成钱包余额缓存的 Redis 键
|
||
// 用途:缓存钱包余额,减少数据库查询
|
||
// 过期时间:5 分钟
|
||
func RedisWalletBalanceKey(walletID uint) string {
|
||
return fmt.Sprintf("wallet:balance:%d", walletID)
|
||
}
|
||
|
||
// RedisRechargeOrderKey 生成充值订单缓存的 Redis 键
|
||
// 用途:充值订单状态查询缓存
|
||
// 过期时间:1 小时
|
||
func RedisRechargeOrderKey(rechargeNo string) string {
|
||
return fmt.Sprintf("recharge:order:%s", rechargeNo)
|
||
}
|
||
|
||
// RedisWalletTransactionKey 生成钱包交易幂等性的 Redis 键
|
||
// 用途:防止重复交易
|
||
// 过期时间:24 小时
|
||
func RedisWalletTransactionKey(requestID string) string {
|
||
return fmt.Sprintf("wallet:transaction:%s", requestID)
|
||
}
|
||
|
||
// ========================================
|
||
// 标签相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisTagCacheKey 生成标签缓存的 Redis 键
|
||
// 用途:缓存热门标签列表
|
||
// 过期时间:1 小时
|
||
func RedisTagCacheKey() string {
|
||
return "tag:cache:list"
|
||
}
|
||
|
||
// RedisResourceTagsKey 生成资源标签关联缓存的 Redis 键
|
||
// 用途:缓存资源的标签列表
|
||
// 过期时间:30 分钟
|
||
func RedisResourceTagsKey(resourceType string, resourceID uint) string {
|
||
return fmt.Sprintf("resource:tags:%s:%d", resourceType, resourceID)
|
||
}
|
||
|
||
// ========================================
|
||
// 权限相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisUserPermissionsKey 生成用户权限列表缓存的 Redis 键
|
||
// 用途:缓存用户的所有权限列表(包含 permCode 和 platform 信息)
|
||
// 格式:JSON 数组 [{"perm_code":"user:list","platform":"web"},...]
|
||
// 过期时间:30 分钟
|
||
func RedisUserPermissionsKey(userID uint) string {
|
||
return fmt.Sprintf("permission:user:%d:list", userID)
|
||
}
|
||
|
||
// ========================================
|
||
// 佣金统计相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisCommissionStatsKey 生成佣金统计缓存的 Redis 键
|
||
// 用途:缓存梯度返佣统计数据(Hash 结构: total_count, total_amount)
|
||
// 过期时间:周期结束后 7 天
|
||
func RedisCommissionStatsKey(allocationID uint, period string) string {
|
||
return fmt.Sprintf("commission:stats:%d:%s", allocationID, period)
|
||
}
|
||
|
||
// RedisCommissionStatsLockKey 生成佣金统计同步锁的 Redis 键
|
||
// 用途:定时同步任务的分布式锁,防止并发同步
|
||
// 过期时间:5 分钟
|
||
func RedisCommissionStatsLockKey() string {
|
||
return "commission:stats:sync:lock"
|
||
}
|
||
|
||
// ========================================
|
||
// 系列分配相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisShopSeriesAllocationKey 生成店铺系列分配缓存的 Redis 键
|
||
// 用途:缓存店铺+系列的分配配置
|
||
// 过期时间:30 分钟
|
||
func RedisShopSeriesAllocationKey(shopID, seriesID uint) string {
|
||
return fmt.Sprintf("shop_series_alloc:%d:%d", shopID, seriesID)
|
||
}
|
||
|
||
// ========================================
|
||
// 轮询系统相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisPollingQueueRealnameKey 生成实名检查轮询队列的 Redis 键
|
||
// 用途:Sorted Set 存储待检查实名状态的卡,Score 为下次检查的 Unix 时间戳
|
||
// 过期时间:无(持久化数据)
|
||
func RedisPollingQueueRealnameKey() string {
|
||
return "polling:queue:realname"
|
||
}
|
||
|
||
// RedisPollingQueueCarddataKey 生成卡流量检查轮询队列的 Redis 键
|
||
// 用途:Sorted Set 存储待检查流量的卡,Score 为下次检查的 Unix 时间戳
|
||
// 过期时间:无(持久化数据)
|
||
func RedisPollingQueueCarddataKey() string {
|
||
return "polling:queue:carddata"
|
||
}
|
||
|
||
// RedisPollingQueuePackageKey 生成套餐检查轮询队列的 Redis 键
|
||
// 用途:Sorted Set 存储待检查套餐的卡,Score 为下次检查的 Unix 时间戳
|
||
// 过期时间:无(持久化数据)
|
||
func RedisPollingQueuePackageKey() string {
|
||
return "polling:queue:package"
|
||
}
|
||
|
||
// RedisPollingCardInfoKey 生成卡信息缓存的 Redis 键
|
||
// 用途:Hash 存储卡的基本信息和轮询状态
|
||
// 过期时间:7 天
|
||
func RedisPollingCardInfoKey(cardID uint) string {
|
||
return fmt.Sprintf("polling:card:%d", cardID)
|
||
}
|
||
|
||
// RedisPollingConfigsCacheKey 生成轮询配置缓存的 Redis 键
|
||
// 用途:String 存储所有轮询配置(JSON 格式)
|
||
// 过期时间:10 分钟
|
||
func RedisPollingConfigsCacheKey() string {
|
||
return "polling:configs"
|
||
}
|
||
|
||
// RedisPollingConfigCardsKey 生成配置匹配索引的 Redis 键
|
||
// 用途:Set 存储匹配该配置的所有卡 ID
|
||
// 过期时间:1 小时
|
||
func RedisPollingConfigCardsKey(configID uint) string {
|
||
return fmt.Sprintf("polling:config:cards:%d", configID)
|
||
}
|
||
|
||
// RedisPollingConcurrencyConfigKey 生成并发控制配置的 Redis 键
|
||
// 用途:String 存储任务类型的最大并发数
|
||
// 过期时间:无(持久化配置)
|
||
func RedisPollingConcurrencyConfigKey(taskType string) string {
|
||
return fmt.Sprintf("polling:concurrency:config:%s", taskType)
|
||
}
|
||
|
||
// RedisPollingConcurrencyCurrentKey 生成并发控制当前值的 Redis 键
|
||
// 用途:String 存储任务类型的当前并发数(计数器)
|
||
// 过期时间:无(实时数据)
|
||
func RedisPollingConcurrencyCurrentKey(taskType string) string {
|
||
return fmt.Sprintf("polling:concurrency:current:%s", taskType)
|
||
}
|
||
|
||
// RedisPollingManualQueueKey 生成手动触发队列的 Redis 键
|
||
// 用途:List 存储手动触发的卡 ID(FIFO 队列)
|
||
// 过期时间:无(临时队列)
|
||
func RedisPollingManualQueueKey(taskType string) string {
|
||
return fmt.Sprintf("polling:manual:%s", taskType)
|
||
}
|
||
|
||
// RedisPollingManualDedupeKey 生成手动触发去重的 Redis 键
|
||
// 用途:Set 存储已加入手动触发队列的卡 ID(用于去重)
|
||
// 过期时间:1小时
|
||
func RedisPollingManualDedupeKey(taskType string) string {
|
||
return fmt.Sprintf("polling:manual:dedupe:%s", taskType)
|
||
}
|
||
|
||
// RedisPollingStatsKey 生成监控统计的 Redis 键
|
||
// 用途:Hash 存储监控指标(成功数、失败数、总耗时等)
|
||
// 过期时间:无(持久化统计)
|
||
func RedisPollingStatsKey(taskType string) string {
|
||
return fmt.Sprintf("polling:stats:%s", taskType)
|
||
}
|
||
|
||
// RedisPollingInitProgressKey 生成初始化进度的 Redis 键
|
||
// 用途:Hash 存储初始化进度信息(总数、已处理数、状态)
|
||
// 过期时间:无(初始化完成后自动删除)
|
||
func RedisPollingInitProgressKey() string {
|
||
return "polling:init:progress"
|
||
}
|
||
|
||
// ========================================
|
||
// 套餐激活锁相关键
|
||
// ========================================
|
||
|
||
// RedisPackageActivationLockKey 生成套餐激活分布式锁的 Redis 键
|
||
// 用途:防止同一载体的套餐激活任务并发执行(排队激活、首次实名激活)
|
||
// 过期时间:30秒(任务执行时间)
|
||
func RedisPackageActivationLockKey(carrierType string, carrierID uint) string {
|
||
return fmt.Sprintf("package:activation:lock:%s:%d", carrierType, carrierID)
|
||
}
|
||
|
||
// ========================================
|
||
// 列表计数缓存 Redis Key
|
||
// ========================================
|
||
|
||
// RedisListCountKey 列表查询计数缓存键
|
||
// 用途:缓存分页列表的 COUNT(*) 结果,避免每次翻页重复全表计数
|
||
// 过期时间:30 秒
|
||
func RedisListCountKey(table string, userID uint, filterHash string) string {
|
||
return fmt.Sprintf("list_count:%s:%d:%s", table, userID, filterHash)
|
||
}
|
||
|
||
// ========================================
|
||
// 订单幂等性相关 Redis Key
|
||
// ========================================
|
||
|
||
// RedisOrderIdempotencyKey 生成订单创建幂等性检测的 Redis 键
|
||
// 用途:防止相同买家在短时间内对同一载体重复下单(SETNX 快速拒绝)
|
||
// 过期时间:3 分钟
|
||
func RedisOrderIdempotencyKey(businessKey string) string {
|
||
return fmt.Sprintf("order:idempotency:%s", businessKey)
|
||
}
|
||
|
||
// RedisOrderCreateLockKey 生成订单创建分布式锁的 Redis 键
|
||
// 用途:防止同一载体的订单创建并发执行
|
||
// 过期时间:10 秒
|
||
func RedisOrderCreateLockKey(carrierType string, carrierID uint) string {
|
||
return fmt.Sprintf("order:create:lock:%s:%d", carrierType, carrierID)
|
||
}
|