ZOCUNT
用于计算有序集合中指定分数区间的成员数量。
Command
$ redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> zadd animal 1 cat 2 dog 3 fish 4 goose
(integer) 4
127.0.0.1:6379> zcount animal 2 3
(integer) 2
Code
func zcount(c redis.Conn) {
defer c.Do("DEL", "animal")
c.Do("ZADD", "animal", 1, "cat", 2, "dog", 3, "fish", 4, "goose")
count, err := c.Do("ZCOUNT", "animal", 2, 3)
if err != nil {
colorlog.Error(err.Error())
return
}
fmt.Println("Specifies the number of members of the score interval is:", count)
}
Output
$ go run main.go
Specifies the number of members of the score interval is: 2