Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
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
}