2023-03-27

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-03-26 22:21:33 +08:00
parent c4da6c74f8
commit 966606afc2
19 changed files with 804 additions and 77 deletions
+28
View File
@@ -2,7 +2,9 @@ package database
import (
"context"
"errors"
"honoka-chan/config"
"strconv"
"github.com/redis/go-redis/v9"
)
@@ -24,3 +26,29 @@ func init() {
panic(err)
}
}
func GetUid(key string) (int, error) {
uid, err := RedisCli.HGet(RedisCtx, "login_key_uid", key).Result()
if err != nil {
return 0, err
}
userId, err := strconv.Atoi(uid)
if err != nil {
return 0, err
}
if userId == 0 {
return 0, errors.New("userId is 0")
}
return userId, nil
}
func MatchTokenUid(token, uid string) bool {
res, err := RedisCli.HGet(RedisCtx, "token_uid", token).Result()
if err != nil {
panic(err)
}
return res == uid
}