func (ut *UserToken) delCache() { conn := config.RedisPool.Get() defer conn.Close() key := "Token:" + ut.Token _, err := conn.Do("DEL", key) if err != nil { log.Err(ae.Redis("", err)) } }
func (ut *UserToken) addUserIdToTokenCache() { conn := config.RedisPool.Get() defer conn.Close() key := "Token:" + ut.Token _, err := conn.Do("HMSET", redis.Args{}.Add(key).AddFlat(ut)...) if err != nil { log.Err(ae.Redis("", err)) } }
func (ut *UserToken) getUserIdFromTokenCache() bool { conn := config.RedisPool.Get() defer conn.Close() v, err := redis.Values(conn.Do("HGETALL", "Token:"+ut.Token)) if len(v) == 0 { return false } if err != nil { log.Err(ae.Redis("", err)) return false } vMap, _ := redis.StringMap(v, nil) ut.UserID, _ = strconv.ParseUint(vMap["user_id"], 10, 64) ut.RefreshToken, _ = vMap["refresh_token"] ut.Created, _ = time.Parse("2006-01-02 15:04:05.999999999 -0700 -0700", vMap["created"]) ut.Expires, _ = time.Parse("2006-01-02 15:04:05.999999999 -0700 -0700", vMap["expires"]) return true }