使用 gtime设置redis时间戳
This commit is contained in:
@@ -3,10 +3,10 @@ package redis
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
@@ -280,7 +280,7 @@ func ClaimPendingMessage(ctx context.Context, streamKey, groupName, consumerName
|
||||
// 使用 gredis SetEX 方法
|
||||
func SetSessionLastActive(ctx context.Context, userId string) error {
|
||||
key := SessionLastActiveKeyPrefix + userId + ":last_active"
|
||||
timestamp := time.Now().Unix()
|
||||
timestamp := gtime.Now().Timestamp()
|
||||
|
||||
// SETEX key 7200 value (7200秒 = 2小时)
|
||||
_, err := GRedisClient.Do(ctx, "SETEX", key, 7200, timestamp)
|
||||
@@ -323,7 +323,7 @@ func IsUserActive(ctx context.Context, userId string, seconds int64) (bool, erro
|
||||
return false, nil // 未找到记录,视为不活跃
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
now := gtime.Now().Timestamp()
|
||||
return (now - lastActive) < seconds, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user