mirror of https://github.com/go-redis/redis.git
Merge branch 'master' into otel
This commit is contained in:
commit
960ff8bd39
|
@ -0,0 +1,83 @@
|
|||
// EXAMPLE: bf_tutorial
|
||||
// HIDE_START
|
||||
package example_commands_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// HIDE_END
|
||||
|
||||
func ExampleClient_bloom() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "bikes:models")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START bloom
|
||||
res1, err := rdb.BFReserve(ctx, "bikes:models", 0.01, 1000).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res1) // >>> OK
|
||||
|
||||
res2, err := rdb.BFAdd(ctx, "bikes:models", "Smoky Mountain Striker").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res2) // >>> true
|
||||
|
||||
res3, err := rdb.BFExists(ctx, "bikes:models", "Smoky Mountain Striker").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res3) // >>> true
|
||||
|
||||
res4, err := rdb.BFMAdd(ctx, "bikes:models",
|
||||
"Rocky Mountain Racer",
|
||||
"Cloudy City Cruiser",
|
||||
"Windy City Wippet",
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res4) // >>> [true true true]
|
||||
|
||||
res5, err := rdb.BFMExists(ctx, "bikes:models",
|
||||
"Rocky Mountain Racer",
|
||||
"Cloudy City Cruiser",
|
||||
"Windy City Wippet",
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res5) // >>> [true true true]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// OK
|
||||
// true
|
||||
// true
|
||||
// [true true true]
|
||||
// [true true true]
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
// EXAMPLE: bitmap_tutorial
|
||||
// HIDE_START
|
||||
package example_commands_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// HIDE_END
|
||||
|
||||
func ExampleClient_ping() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "pings:2024-01-01-00:00")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START ping
|
||||
res1, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res1) // >>> 0
|
||||
|
||||
res2, err := rdb.GetBit(ctx, "pings:2024-01-01-00:00", 123).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res2) // >>> 1
|
||||
|
||||
res3, err := rdb.GetBit(ctx, "pings:2024-01-01-00:00", 456).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res3) // >>> 0
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 0
|
||||
// 1
|
||||
// 0
|
||||
}
|
||||
|
||||
func ExampleClient_bitcount() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
_, err := rdb.SetBit(ctx, "pings:2024-01-01-00:00", 123, 1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START bitcount
|
||||
res4, err := rdb.BitCount(ctx, "pings:2024-01-01-00:00",
|
||||
&redis.BitCount{
|
||||
Start: 0,
|
||||
End: 456,
|
||||
}).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res4) // >>> 1
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 1
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,251 @@
|
|||
// EXAMPLE: tdigest_tutorial
|
||||
// HIDE_START
|
||||
package example_commands_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// HIDE_END
|
||||
|
||||
func ExampleClient_tdigstart() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "racer_ages", "bikes:sales")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START tdig_start
|
||||
res1, err := rdb.TDigestCreate(ctx, "bikes:sales").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res1) // >>> OK
|
||||
|
||||
res2, err := rdb.TDigestAdd(ctx, "bikes:sales", 21).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res2) // >>> OK
|
||||
|
||||
res3, err := rdb.TDigestAdd(ctx, "bikes:sales",
|
||||
150, 95, 75, 34,
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res3) // >>> OK
|
||||
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// OK
|
||||
// OK
|
||||
// OK
|
||||
}
|
||||
|
||||
func ExampleClient_tdigcdf() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "racer_ages", "bikes:sales")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START tdig_cdf
|
||||
res4, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res4) // >>> OK
|
||||
|
||||
res5, err := rdb.TDigestAdd(ctx, "racer_ages",
|
||||
45.88, 44.2, 58.03, 19.76, 39.84, 69.28,
|
||||
50.97, 25.41, 19.27, 85.71, 42.63,
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res5) // >>> OK
|
||||
|
||||
res6, err := rdb.TDigestRank(ctx, "racer_ages", 50).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res6) // >>> [7]
|
||||
|
||||
res7, err := rdb.TDigestRank(ctx, "racer_ages", 50, 40).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res7) // >>> [7 4]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// OK
|
||||
// OK
|
||||
// [7]
|
||||
// [7 4]
|
||||
}
|
||||
|
||||
func ExampleClient_tdigquant() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "racer_ages")
|
||||
// REMOVE_END
|
||||
|
||||
_, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = rdb.TDigestAdd(ctx, "racer_ages",
|
||||
45.88, 44.2, 58.03, 19.76, 39.84, 69.28,
|
||||
50.97, 25.41, 19.27, 85.71, 42.63,
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// STEP_START tdig_quant
|
||||
res8, err := rdb.TDigestQuantile(ctx, "racer_ages", 0.5).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res8) // >>> [44.2]
|
||||
|
||||
res9, err := rdb.TDigestByRank(ctx, "racer_ages", 4).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res9) // >>> [42.63]
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// [44.2]
|
||||
// [42.63]
|
||||
}
|
||||
|
||||
func ExampleClient_tdigmin() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "racer_ages")
|
||||
// REMOVE_END
|
||||
|
||||
_, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = rdb.TDigestAdd(ctx, "racer_ages",
|
||||
45.88, 44.2, 58.03, 19.76, 39.84, 69.28,
|
||||
50.97, 25.41, 19.27, 85.71, 42.63,
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// STEP_START tdig_min
|
||||
res10, err := rdb.TDigestMin(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res10) // >>> 19.27
|
||||
|
||||
res11, err := rdb.TDigestMax(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res11) // >>> 85.71
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// 19.27
|
||||
// 85.71
|
||||
}
|
||||
|
||||
func ExampleClient_tdigreset() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "racer_ages")
|
||||
// REMOVE_END
|
||||
_, err := rdb.TDigestCreate(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// STEP_START tdig_reset
|
||||
res12, err := rdb.TDigestReset(ctx, "racer_ages").Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(res12) // >>> OK
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// OK
|
||||
}
|
2
go.mod
2
go.mod
|
@ -10,6 +10,6 @@ require (
|
|||
)
|
||||
|
||||
retract (
|
||||
v9.5.3 // This version was accidentally released. Please use version 9.6.0 instead.
|
||||
v9.5.4 // This version was accidentally released. Please use version 9.6.0 instead.
|
||||
v9.5.3 // This version was accidentally released. Please use version 9.6.0 instead.
|
||||
)
|
||||
|
|
|
@ -1446,16 +1446,18 @@ var _ = Describe("RediSearch commands Resp 3", Label("search"), func() {
|
|||
|
||||
options := &redis.FTAggregateOptions{Apply: []redis.FTAggregateApply{{Field: "@CreatedDateTimeUTC * 10", As: "CreatedDateTimeUTC"}}}
|
||||
res, err := client.FTAggregateWithArgs(ctx, "idx1", "*", options).RawResult()
|
||||
rawVal := client.FTAggregateWithArgs(ctx, "idx1", "*", options).RawVal()
|
||||
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(rawVal).To(BeEquivalentTo(res))
|
||||
results := res.(map[interface{}]interface{})["results"].([]interface{})
|
||||
Expect(results[0].(map[interface{}]interface{})["extra_attributes"].(map[interface{}]interface{})["CreatedDateTimeUTC"]).
|
||||
To(Or(BeEquivalentTo("6373878785249699840"), BeEquivalentTo("6373878758592700416")))
|
||||
Expect(results[1].(map[interface{}]interface{})["extra_attributes"].(map[interface{}]interface{})["CreatedDateTimeUTC"]).
|
||||
To(Or(BeEquivalentTo("6373878785249699840"), BeEquivalentTo("6373878758592700416")))
|
||||
|
||||
rawVal := client.FTAggregateWithArgs(ctx, "idx1", "*", options).RawVal()
|
||||
rawValResults := rawVal.(map[interface{}]interface{})["results"].([]interface{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(rawValResults[0]).To(Or(BeEquivalentTo(results[0]), BeEquivalentTo(results[1])))
|
||||
Expect(rawValResults[1]).To(Or(BeEquivalentTo(results[0]), BeEquivalentTo(results[1])))
|
||||
|
||||
// Test with UnstableResp3 false
|
||||
Expect(func() {
|
||||
options = &redis.FTAggregateOptions{Apply: []redis.FTAggregateApply{{Field: "@CreatedDateTimeUTC * 10", As: "CreatedDateTimeUTC"}}}
|
||||
|
|
Loading…
Reference in New Issue