فهرست منبع

🔧 fix(redis): only set expiration if greater than 0 in RedisHSetObj

RedwindA 8 ماه پیش
والد
کامیت
a7d87475af
1فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 5 1
      common/redis.go

+ 5 - 1
common/redis.go

@@ -141,7 +141,11 @@ func RedisHSetObj(key string, obj interface{}, expiration time.Duration) error {
 
 
 	txn := RDB.TxPipeline()
 	txn := RDB.TxPipeline()
 	txn.HSet(ctx, key, data)
 	txn.HSet(ctx, key, data)
-	txn.Expire(ctx, key, expiration)
+
+	// 只有在 expiration 大于 0 时才设置过期时间
+	if expiration > 0 {
+		txn.Expire(ctx, key, expiration)
+	}
 
 
 	_, err := txn.Exec(ctx)
 	_, err := txn.Exec(ctx)
 	if err != nil {
 	if err != nil {