CacheGetTokenByKey 从缓存中获取 token,如果缓存中不存在,则从数据库中获取
(key string)
| 50 | |
| 51 | // CacheGetTokenByKey 从缓存中获取 token,如果缓存中不存在,则从数据库中获取 |
| 52 | func 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 | } |
no test coverage detected