func ZRevRangeByScore(key string, min float64, max float64) (sList []string, err error) { sList, err = gClient.ZRevRangeByScore(key, redis.ZRangeByScore{ Min: kmgStrconv.FormatFloat(min), Max: kmgStrconv.FormatFloat(max), }).Result() if err == nil { return sList, err } if isRedisErrorWrongType(err) { return nil, ErrSortedSetWrongType } return nil, err }
func ZRangeByScoreWithScore(key string, min float64, max float64) (zList []Z, err error) { zList1, err := gClient.ZRangeByScoreWithScores(key, redis.ZRangeByScore{ Min: kmgStrconv.FormatFloat(min), Max: kmgStrconv.FormatFloat(max), }).Result() if err == nil { return ZListFromRedisZ(zList1), err } if isRedisErrorWrongType(err) { return nil, ErrSortedSetWrongType } return nil, err }
//缓存时间为1天 func MustGetExchangeRateWithCache(from string, to string) float64 { b, err := kmgCache.FileTtlCache("MustGetExchangeRateWithCache_"+from+"_"+to, func() (b []byte, ttl time.Duration, err error) { f := MustGetExchangeRate(from, to) return []byte(kmgStrconv.FormatFloat(f)), kmgTime.Day, nil }) if err != nil { panic(err) } f, err := kmgStrconv.ParseFloat64(string(b)) if err != nil { panic(err) } return f }
func NewChartFromTimeFloatPairWithTitle(title string, inputList []TimeFloatPair) kmgBootstrap.Panel { var body kmgView.HtmlRenderer if len(inputList) > 1 { body = CreateLineFromTimeFloatPair(inputList) } else { out := fmt.Sprintf("共 %d 条数据\n", len(inputList)) for _, pair := range inputList { out += kmgTime.DefaultFormat(pair.X) + " : " + kmgStrconv.FormatFloat(pair.Y) + " \n" } body = kmgBootstrap.Pre(out) } return kmgBootstrap.Panel{ Title: title + " 共 " + kmgStrconv.FormatInt(len(inputList)) + " 条数据", Body: body, } }
func FloatToString(t Transformer, in reflect.Value, out reflect.Value) (err error) { f := in.Float() fs := kmgStrconv.FormatFloat(f) out.SetString(fs) return }
func MustZRemRangeByScore(key string, min float64, max float64) { err := gClient.ZRemRangeByScore(key, kmgStrconv.FormatFloat(min), kmgStrconv.FormatFloat(max)).Err() if err != nil { panic(err) } }