Skip to content

Commit 66abd9e

Browse files
authored
fix: redis save error when KickTokens (#3002)
1 parent 8702529 commit 66abd9e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pkg/common/storage/cache/redis/token.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package redis
22

33
import (
44
"context"
5+
"strconv"
6+
"sync"
7+
"time"
8+
59
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache"
610
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/cachekey"
711
"github.com/openimsdk/tools/errs"
812
"github.com/redis/go-redis/v9"
9-
"strconv"
10-
"sync"
11-
"time"
1213
)
1314

1415
type tokenCache struct {
@@ -99,7 +100,7 @@ func (c *tokenCache) SetTokenMapByUidPid(ctx context.Context, userID string, pla
99100
return errs.Wrap(c.rdb.HSet(ctx, cachekey.GetTokenKey(userID, platformID), mm).Err())
100101
}
101102

102-
func (c *tokenCache) BatchSetTokenMapByUidPid(ctx context.Context, tokens map[string]map[string]int) error {
103+
func (c *tokenCache) BatchSetTokenMapByUidPid(ctx context.Context, tokens map[string]map[string]any) error {
103104
pipe := c.rdb.Pipeline()
104105
for k, v := range tokens {
105106
pipe.HSet(ctx, k, v)

pkg/common/storage/cache/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ type TokenModel interface {
1111
GetTokensWithoutError(ctx context.Context, userID string, platformID int) (map[string]int, error)
1212
GetAllTokensWithoutError(ctx context.Context, userID string) (map[int]map[string]int, error)
1313
SetTokenMapByUidPid(ctx context.Context, userID string, platformID int, m map[string]int) error
14-
BatchSetTokenMapByUidPid(ctx context.Context, tokens map[string]map[string]int) error
14+
BatchSetTokenMapByUidPid(ctx context.Context, tokens map[string]map[string]any) error
1515
DeleteTokenByUidPid(ctx context.Context, userID string, platformID int, fields []string) error
1616
}

pkg/common/storage/controller/auth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controller
22

33
import (
44
"context"
5+
56
"github.com/golang-jwt/jwt/v4"
67
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
78
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
@@ -56,7 +57,7 @@ func (a *authDatabase) SetTokenMapByUidPid(ctx context.Context, userID string, p
5657
}
5758

5859
func (a *authDatabase) BatchSetTokenMapByUidPid(ctx context.Context, tokens []string) error {
59-
setMap := make(map[string]map[string]int)
60+
setMap := make(map[string]map[string]any)
6061
for _, token := range tokens {
6162
claims, err := tokenverify.GetClaimFromToken(token, authverify.Secret(a.accessSecret))
6263
key := cachekey.GetTokenKey(claims.UserID, claims.PlatformID)
@@ -66,7 +67,7 @@ func (a *authDatabase) BatchSetTokenMapByUidPid(ctx context.Context, tokens []st
6667
if v, ok := setMap[key]; ok {
6768
v[token] = constant.KickedToken
6869
} else {
69-
setMap[key] = map[string]int{
70+
setMap[key] = map[string]any{
7071
token: constant.KickedToken,
7172
}
7273
}

0 commit comments

Comments
 (0)