1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| func SortedSet() { key1, key2 := "zset1", "zset2" rdb.Del(ctx, key1, key2)
rand.Seed(time.Now().UnixNano())
for i := 0; i < 10; i++ { score := float64(rand.Intn(100)) member := "golang-" + strconv.Itoa(i) data := &redis.Z{ score, member, } rdb.ZAdd(ctx, key1, data) }
for i := 0; i < 10; i++ { score := float64(rand.Intn(100)) member := "golang-" + strconv.Itoa(i) data := &redis.Z{ score, member, } rdb.ZAdd(ctx, key2, data) }
n1 := rdb.ZCard(ctx, key1) fmt.Println(n1)
s1 := rdb.ZScore(ctx, key1, "golang-3").Val() fmt.Println(s1)
v1 := rdb.ZIncrBy(ctx, key1, 50, "golang-3").Val() fmt.Println(v1)
s2 := rdb.ZRank(ctx, key1, "golang-3").Val() fmt.Println(s2)
s3 := rdb.ZRevRank(ctx, key1, "golang-3").Val() fmt.Println(s3)
s4 := rdb.ZRange(ctx, key1, 0, -1).Val() fmt.Println(s4)
s5 := rdb.ZRevRange(ctx, key2, 0, -1).Val() fmt.Println(s5)
v2 := rdb.ZRem(ctx, key2, "golang-3").Val() fmt.Println(v2)
key3, key4 := "zset3", "zset4" kslice := []string{key1, key2} wslice := []float64{1.00, 1.00} z := &redis.ZStore{ kslice, wslice, "SUM", }
r1 := rdb.ZInterStore(ctx, key3, z).Val() fmt.Println(r1)
r2 := rdb.ZUnionStore(ctx, key4, z).Val() fmt.Println(r2) }
|