mirror of
				https://github.com/redis/go-redis.git
				synced 2025-11-04 02:33:24 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			454 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			454 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
	"fmt"
 | 
						|
 | 
						|
	"github.com/redis/go-redis/v9"
 | 
						|
)
 | 
						|
 | 
						|
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)
 | 
						|
}
 |