package main import ( "context" "fmt" "github.com/go-redis/redis/v9" ) func main() { opt, err := redis.ParseURL("redis://default:yourPassword@192.168.157.135:6379/0?dial_timeout=1") if err != nil { panic(err) } client := redis.NewClient(opt) ctx := context.Background() result := client.HSet(ctx, "students", "42001", "Mashibing", "42002", "GoLang", "42003", "Redis") fmt.Println(result.Result()) fmt.Println(client.HGetAll(ctx, "students").Result()) fmt.Println( client.HLen(ctx, "students"). Result()) // 3 fmt.Println( client.HRandField(ctx, "students", 2). Result()) // [42003 42001] , [42002 42003] fmt.Println( client.HRandField(ctx, "students", -2). Result()) // [42003 42001] , [42003 42003] fmt.Println( client.HRandFieldWithValues(ctx, "students", 2). Result()) // [{42002 GoLang} {42003 Redis}] fmt.Println( client.HExists(ctx, "students", "42003"). Result()) // true fmt.Println( client.HExists(ctx, "students", "42006"). Result()) // false fmt.Println( client.HDel(ctx, "students", "42003"). Result()) // 1 fmt.Println( client.HExists(ctx, "students", "42003"). Result()) // false fmt.Println( client.Do(ctx, "HSTRLEN", "students", "42001"). Result()) // 9 }