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