redis/example/hll/main.go

31 lines
454 B
Go
Raw Permalink Normal View History

2022-03-17 15:30:55 +03:00
package main
import (
"context"
"fmt"
2023-01-23 09:48:54 +03:00
"github.com/redis/go-redis/v9"
2022-03-17 15:30:55 +03:00
)
func main() {
ctx := context.Background()
rdb := redis.NewClient(&redis.Options{
Addr: ":6379",
})
_ = rdb.FlushDB(ctx).Err()
for i := 0; i < 10; i++ {
if err := rdb.PFAdd(ctx, "myset", fmt.Sprint(i)).Err(); err != nil {
panic(err)
}
}
card, err := rdb.PFCount(ctx, "myset").Result()
if err != nil {
panic(err)
}
fmt.Println("set cardinality", card)
}