分享码有效期,支持表达式
This commit is contained in:
Vendored
+3
-4
@@ -2,14 +2,14 @@
|
||||
//
|
||||
// # Redis 存储结构
|
||||
//
|
||||
// share:{code} Hash, TTL 30min — 分享码主数据
|
||||
// share:{code} Hash, TTL = SHARE_CODE_TTL_MIN — 分享码主数据
|
||||
// mac_addr 创建者 MAC 地址
|
||||
// ip_addr 创建者 IP
|
||||
// eq_data EQ 参数 JSON
|
||||
// expire_at 过期时间 (RFC3339)
|
||||
// persisted 是否已刷入 DB ("0"/"1")
|
||||
//
|
||||
// share:mac:{mac} ZSET, TTL 1h (兜底) — MAC 二级索引 (查询时主动清理过期成员)
|
||||
// share:mac:{mac} ZSET, TTL = SHARE_CODE_TTL_MIN — MAC 二级索引 (查询时主动清理过期成员)
|
||||
// member = share_code
|
||||
// score = expire_at unix timestamp
|
||||
//
|
||||
@@ -51,7 +51,6 @@ const (
|
||||
shareImportFlushLockPref = "share:import:flush:lock:"
|
||||
shareMacIndexPrefix = "share:mac:"
|
||||
shareCodeLength = 5
|
||||
shareMacIndexTTL = 1 * time.Hour
|
||||
shareImportPendingTTL = 12 * time.Hour
|
||||
shareCodeCharset = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"
|
||||
shareCodeMaxRetries = 20
|
||||
@@ -126,7 +125,7 @@ func (c *ShareCodeCache) Create(ctx context.Context, macAddr, ipAddr string, eqD
|
||||
key := shareCodeKey(code)
|
||||
macIdxKey := shareMacIndexKey(macAddr)
|
||||
ok, err := shareCreateScript.Run(ctx, c.rdb, []string{key, sharePendingSet, macIdxKey},
|
||||
macAddr, ipAddr, eqJSON, expireAt.Format(time.RFC3339), int(c.codeTTL.Seconds()), code, expireAt.Unix(), int(shareMacIndexTTL.Seconds()),
|
||||
macAddr, ipAddr, eqJSON, expireAt.Format(time.RFC3339), int(c.codeTTL.Seconds()), code, expireAt.Unix(), int(c.codeTTL.Seconds()),
|
||||
).Int()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create share code in redis: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user