分享码日志新增 model 字段,记录操作的设备的型号 X8/X9
This commit is contained in:
Vendored
+17
-9
@@ -5,6 +5,7 @@
|
||||
// share:{code} Hash, TTL = SHARE_CODE_TTL_MIN — 分享码主数据
|
||||
// mac_addr 创建者 MAC 地址
|
||||
// ip_addr 创建者 IP
|
||||
// model 操作设备型号
|
||||
// eq_data EQ 参数 JSON
|
||||
// expire_at 过期时间 (RFC3339)
|
||||
// persisted 是否已刷入 DB ("0"/"1")
|
||||
@@ -57,6 +58,7 @@ const (
|
||||
|
||||
fieldMacAddr = "mac_addr"
|
||||
fieldIPAddr = "ip_addr"
|
||||
fieldModel = "model"
|
||||
fieldEqData = "eq_data"
|
||||
fieldExpireAt = "expire_at"
|
||||
fieldPersisted = "persisted"
|
||||
@@ -69,21 +71,23 @@ end
|
||||
redis.call('HSET', KEYS[1],
|
||||
'mac_addr', ARGV[1],
|
||||
'ip_addr', ARGV[2],
|
||||
'eq_data', ARGV[3],
|
||||
'expire_at', ARGV[4],
|
||||
'model', ARGV[3],
|
||||
'eq_data', ARGV[4],
|
||||
'expire_at', ARGV[5],
|
||||
'persisted', '0'
|
||||
)
|
||||
redis.call('EXPIRE', KEYS[1], tonumber(ARGV[5]))
|
||||
redis.call('SADD', KEYS[2], ARGV[6])
|
||||
redis.call('EXPIRE', KEYS[1], tonumber(ARGV[6]))
|
||||
redis.call('SADD', KEYS[2], ARGV[7])
|
||||
-- ZSET: score = expire_at unix timestamp, member = share code
|
||||
redis.call('ZADD', KEYS[3], tonumber(ARGV[7]), ARGV[6])
|
||||
redis.call('EXPIRE', KEYS[3], tonumber(ARGV[8]))
|
||||
redis.call('ZADD', KEYS[3], tonumber(ARGV[8]), ARGV[7])
|
||||
redis.call('EXPIRE', KEYS[3], tonumber(ARGV[9]))
|
||||
return 1
|
||||
`)
|
||||
|
||||
type ShareImportPendingLog struct {
|
||||
MacAddr string `json:"mac_addr"`
|
||||
ShareCode string `json:"share_code"`
|
||||
Model string `json:"model"`
|
||||
IpAddr string `json:"ip_addr"`
|
||||
EqData string `json:"eq_data"`
|
||||
ExpireAt string `json:"expire_at"`
|
||||
@@ -93,6 +97,7 @@ type ShareCodeData struct {
|
||||
ShareCode string
|
||||
MacAddr string
|
||||
IpAddr string
|
||||
Model string
|
||||
EqData string
|
||||
ExpireAt time.Time
|
||||
Persisted bool
|
||||
@@ -112,7 +117,7 @@ func (c *ShareCodeCache) ShareCodeTTL() time.Duration {
|
||||
return c.codeTTL
|
||||
}
|
||||
|
||||
func (c *ShareCodeCache) Create(ctx context.Context, macAddr, ipAddr string, eqData []byte) (*ShareCodeData, error) {
|
||||
func (c *ShareCodeCache) Create(ctx context.Context, macAddr, ipAddr, model string, eqData []byte) (*ShareCodeData, error) {
|
||||
expireAt := time.Now().Add(c.codeTTL)
|
||||
eqJSON := string(eqData)
|
||||
|
||||
@@ -125,7 +130,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(c.codeTTL.Seconds()),
|
||||
macAddr, ipAddr, model, 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)
|
||||
@@ -135,6 +140,7 @@ func (c *ShareCodeCache) Create(ctx context.Context, macAddr, ipAddr string, eqD
|
||||
ShareCode: code,
|
||||
MacAddr: macAddr,
|
||||
IpAddr: ipAddr,
|
||||
Model: model,
|
||||
EqData: eqJSON,
|
||||
ExpireAt: expireAt,
|
||||
Persisted: false,
|
||||
@@ -164,6 +170,7 @@ func (c *ShareCodeCache) Get(ctx context.Context, shareCode string) (*ShareCodeD
|
||||
ShareCode: shareCode,
|
||||
MacAddr: values[fieldMacAddr],
|
||||
IpAddr: values[fieldIPAddr],
|
||||
Model: values[fieldModel],
|
||||
EqData: values[fieldEqData],
|
||||
ExpireAt: expireAt,
|
||||
Persisted: values[fieldPersisted] == "1",
|
||||
@@ -208,11 +215,12 @@ func (c *ShareCodeCache) MarkPersisted(ctx context.Context, shareCode string) er
|
||||
return c.rdb.SRem(ctx, sharePendingSet, shareCode).Err()
|
||||
}
|
||||
|
||||
func (c *ShareCodeCache) EnqueueImportLog(ctx context.Context, macAddr, shareCode, ipAddr, eqData string, expireAt time.Time) error {
|
||||
func (c *ShareCodeCache) EnqueueImportLog(ctx context.Context, macAddr, shareCode, model, ipAddr, eqData string, expireAt time.Time) error {
|
||||
field := fmt.Sprintf("%s:%s", macAddr, shareCode) // 同 MAC+code 幂等,避免重复导入产生多条记录
|
||||
payload, err := json.Marshal(ShareImportPendingLog{
|
||||
MacAddr: macAddr,
|
||||
ShareCode: shareCode,
|
||||
Model: model,
|
||||
IpAddr: ipAddr,
|
||||
EqData: eqData,
|
||||
ExpireAt: expireAt.Format(time.RFC3339),
|
||||
|
||||
Reference in New Issue
Block a user