func delValue(key string) bool { conn := common.GetRedisPool().Get() _, err := conn.Do("del", key) defer conn.Close() if err != nil { fmt.Println("Method - delValue : ", err) return false } return true }
func setValue(key, value string) bool { conn := common.GetRedisPool().Get() _, err := conn.Do("set", key, value) defer conn.Close() if err != nil { fmt.Println("Method - setValue : ", err) return false } return true }
func getValue(key string) string { conn := common.GetRedisPool().Get() ret, err := redis.String(conn.Do("get", key)) defer conn.Close() if err != nil { fmt.Println("Method - getValue : ", err) return "" } return ret }
func SaveVerifyCode(mobile string, code int) bool { conn := common.GetRedisPool().Get() key := "verify_code_" + mobile VerifyInfo := VerifyCode{Mobile: mobile, Code: code, Create_time: time.Now().Unix()} strValue, err := json.Marshal(VerifyInfo) if err != nil { fmt.Println("SaveVerifyCode - : ", err) return false } _, err = conn.Do("set", key, strValue) defer conn.Close() if err != nil { fmt.Println("SaveVerifyCode - : ", err) return false } return true }
func VerifyCodeCheck(mobile string, code int) bool { conn := common.GetRedisPool().Get() key := "verify_code_" + mobile ret, err := redis.String(conn.Do("get", key)) defer conn.Close() if err != nil { fmt.Println("VerifyCodeCheck - : ", err) return false } VerifyInfo := VerifyCode{} err = json.Unmarshal([]byte(ret), &VerifyInfo) if err != nil { fmt.Println("VerifyCodeCheck - : ", err) return false } if VerifyInfo.Create_time+ValidTime >= time.Now().Unix() && VerifyInfo.Code == code { return true } return false }
func Get_Verify_Code(mobile string) (code int, ok bool) { conn := common.GetRedisPool().Get() key := "verify_code_" + mobile ret, err := redis.String(conn.Do("get", key)) defer conn.Close() if err != nil { fmt.Println("VerifyCodeCheck - : ", err) return 0, false } VerifyInfo := VerifyCode{} err = json.Unmarshal([]byte(ret), &VerifyInfo) if err != nil { fmt.Println("VerifyCodeCheck - : ", err) return 0, false } if VerifyInfo.Create_time+RefreshTime >= time.Now().Unix() { return VerifyInfo.Code, true } return 0, false }