MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / cacheGetTokenByKey

Function cacheGetTokenByKey

model/token_cache.go:52–64  ·  view source on GitHub ↗

CacheGetTokenByKey 从缓存中获取 token,如果缓存中不存在,则从数据库中获取

(key string)

Source from the content-addressed store, hash-verified

50
51// CacheGetTokenByKey 从缓存中获取 token,如果缓存中不存在,则从数据库中获取
52func cacheGetTokenByKey(key string) (*Token, error) {
53 hmacKey := common.GenerateHMAC(key)
54 if !common.RedisEnabled {
55 return nil, fmt.Errorf("redis is not enabled")
56 }
57 var token Token
58 err := common.RedisHGetObj(fmt.Sprintf("token:%s", hmacKey), &token)
59 if err != nil {
60 return nil, err
61 }
62 token.Key = key
63 return &token, nil
64}

Callers 1

GetTokenByKeyFunction · 0.85

Calls 2

GenerateHMACFunction · 0.92
RedisHGetObjFunction · 0.92

Tested by

no test coverage detected