feat(app): update
This commit is contained in:
2
pkg/cache/redis_client.go
vendored
2
pkg/cache/redis_client.go
vendored
@ -1,8 +1,8 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
logs "servicebase/pkg/log"
|
||||
"context"
|
||||
logs "servicebase/pkg/log"
|
||||
|
||||
redis "github.com/redis/go-redis/v9"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
6
pkg/cache/redis_lock.go
vendored
6
pkg/cache/redis_lock.go
vendored
@ -1,8 +1,8 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"servicebase/pkg/log"
|
||||
"errors"
|
||||
"servicebase/pkg/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -10,7 +10,7 @@ func Lock(key string) (e error) {
|
||||
var success bool
|
||||
TryMax := 6
|
||||
redisClient := GetCommonRedisInstance().RedisClient
|
||||
for i := 0; i < TryMax; i++ {
|
||||
for range TryMax {
|
||||
success, e = redisClient.SetNX(Ctx(), key, time.Now(), time.Millisecond*1000*3).Result()
|
||||
if e != nil {
|
||||
log.Info("Lock GetCommonRedisInstance error: " + e.Error())
|
||||
@ -46,7 +46,7 @@ func RedisLockGetTime(key string, duration time.Duration) (e error) {
|
||||
func RedisLockGet(key string) (e error) {
|
||||
redisClient := GetCommonRedisInstance().RedisClient
|
||||
success := false
|
||||
for i := 0; i < TryMax; i++ {
|
||||
for range TryMax {
|
||||
success, e = redisClient.SetNX(Ctx(), key, time.Now(), LockTimeout).Result()
|
||||
if nil != e {
|
||||
return
|
||||
|
||||
4
pkg/cache/user/user.go
vendored
4
pkg/cache/user/user.go
vendored
@ -1,9 +1,9 @@
|
||||
package cache_user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"servicebase/pkg/cache"
|
||||
"servicebase/pkg/tools"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -14,11 +14,9 @@ import (
|
||||
const key = "user:models"
|
||||
const keyToken = "user:token"
|
||||
|
||||
// 用户当前所在的房间ID + userid = chatroomid
|
||||
const ACCESSTOKEN_KEY_PREV = "ACCESSTOKEN_"
|
||||
const ACCESSTOKEN_EXPIRE_DURATION = time.Hour * 24 * 180
|
||||
|
||||
// 通过token获取userId
|
||||
func IdByToken(token string) (userId string) {
|
||||
if len(token) == 0 {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user