-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
作者这里的的缓存 InitUserInfo()
方法有问题吧
如果用 user_key
作为缓存的 key :
- 第二帐户登录的时候,缓存会覆盖。
- 如果这时候,第一个帐户的 token没有过期,然后在
task
中调用GetUserInfo()
, 拿到的是第二个用户的信息。
micro-todoList/pkg/ctl/user_info.go
Lines 12 to 36 in 499cb5a
var userKey string = "user_key" | |
type UserInfo struct { | |
Id uint `json:"id"` | |
} | |
func InitUserInfo(ctx context.Context, user *UserInfo) error { | |
cachedUser, err := GetUserInfo(ctx) | |
if err != nil { | |
return err | |
} | |
// 如果缓存中存在用户信息,直接返回 | |
if cachedUser != nil { | |
return nil | |
} | |
// 如果缓存中不存在用户信息,将用户信息存储到缓存中 | |
if err := SetUserInCache(ctx, user, cache.RedisClient); err != nil { | |
return err | |
} | |
return nil | |
} | |
Metadata
Metadata
Assignees
Labels
No labels