func (r RedisController) SortSet() error { opType := r.GetParam("opType") key := r.GetParam("key") if opType == "1" { zs := []*redis.Z{ {Member: "小张",Score: 88}, {Member: "小李",Score: 90}, {Member: "小明",Score: 80}, {Member: "小英",Score: 70}, {Member: "小赵",Score: 95}, {Member: "小王",Score: 75}, {Member: "笨蛋",Score: 40}, } result, err := RedisClient.ZAdd(ctx, key, zs...).Result() if err != nil { return r.Error(err.Error()) } return r.Success(result) } else { resultMap := make(map[string]interface{}) val := RedisClient.ZCard(ctx, key).Val() resultMap["获取成员数"] = val resultMap["70分-90分成员数"] = RedisClient.ZCount(ctx, key, "70", "90").Val() result, _ := RedisClient.ZRevRangeByScoreWithScores(ctx, key, &redis.ZRangeBy{ Min: "0", Max: "100", Offset: 0, Count: 3, }).Result() resultMap["分数前三排名"] = result f, _ := RedisClient.ZScore(ctx, key, "小张").Result() resultMap["小张的分数"] = f f2, err := RedisClient.ZIncrBy(ctx, key, 60.0, "笨蛋").Result() fmt.Println(err) fmt.Printf("新分数:%v \n",f2) result2, _ := RedisClient.ZRevRangeByScoreWithScores(ctx, key, &redis.ZRangeBy{ Min: "0", Max: "100", Offset: 0, Count: 3, }).Result() resultMap["调整分后排名"] = result2 return r.Success(resultMap) }
|