Skip to content

Commit

Permalink
example
Browse files Browse the repository at this point in the history
  • Loading branch information
AvitalFineRedis committed Jun 9, 2021
1 parent 41854dc commit 3e9191b
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions example_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 3e9191b

Please sign in to comment.