diff --git a/example_client_test.go b/example_client_test.go index d9d9a3d..97b8ce7 100644 --- a/example_client_test.go +++ b/example_client_test.go @@ -50,3 +50,76 @@ func ExampleNewClientFromPool() { // Output: myItem exists in mytest: true } + +// exemplifies the TdCreate function +func ExampleTdCreate() { + host := "localhost:6379" + var client = redisbloom.NewClient(host, "nohelp", nil) + + ret, err := client.TdCreate("key", 100) + if err != nil { + fmt.Println("Error:", err) + } + + fmt.Println(ret) + // Output: OK + +} + +// exemplifies the TdCreate function +func ExampleTdAdd() { + host := "localhost:6379" + var client = redisbloom.NewClient(host, "nohelp", nil) + + key := "example" + ret, err := client.TdCreate(key, 100) + if err != nil { + fmt.Println("Error:", err) + } + + samples := map[float64]float64{1.0: 1.0, 2.0: 2.0} + ret, err = client.TdAdd(key, samples) + if err != nil { + fmt.Println("Error:", err) + } + + fmt.Println(ret) + // Output: OK + +} + +// exemplifies the TdMin TdMax and TdCdf functions +func ExampleTdQuery() { + host := "localhost:6379" + var client = redisbloom.NewClient(host, "nohelp", nil) + + key := "example" + _, err := client.TdCreate(key, 10) + if err != nil { + fmt.Println("Error:", err) + } + + samples := map[float64]float64{1.0: 1.0, 2.0: 2.0, 3.0: 3.0} + _, err = client.TdAdd(key, samples) + if err != nil { + fmt.Println("Error:", err) + } + + min, err := client.TdMin(key) + if err != nil { + fmt.Println("Error:", err) + } + + max, err := client.TdMax(key) + if err != nil { + fmt.Println("Error:", err) + } + + cdf, err := client.TdCdf(key, 0.0) + if err != nil { + fmt.Println("Error:", err) + } + + fmt.Println(min, max, cdf) + // Output: 1 3 0 +}