MCPcopy
hub / github.com/redis/go-redis / ExampleClient_timeseries_agg_bucket

Function ExampleClient_timeseries_agg_bucket

doctests/timeseries_tut_test.go:695–774  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

693 // [{0 [1.8 2.1]} {2 [1.9 2.3]} {4 [1.78 1.78]}]
694}
695func ExampleClient_timeseries_agg_bucket() {
696 ctx := context.Background()
697
698 rdb := redis.NewClient(&redis.Options{
699 Addr: "localhost:6379",
700 Password: "", // no password set
701 DB: 0, // use default DB
702 })
703
704 // REMOVE_START
705 // make sure we are working with fresh database
706 rdb.FlushDB(ctx)
707 rdb.Del(ctx, "sensor3")
708 // REMOVE_END
709
710 // STEP_START agg_bucket
711 res1, err := rdb.TSCreate(ctx, "sensor3").Result()
712 if err != nil {
713 panic(err)
714 }
715
716 fmt.Println(res1) // >>> OK
717
718 res2, err := rdb.TSMAdd(ctx, [][]interface{}{
719 {"sensor3", 10, 1000},
720 {"sensor3", 20, 2000},
721 {"sensor3", 30, 3000},
722 {"sensor3", 40, 4000},
723 {"sensor3", 50, 5000},
724 {"sensor3", 60, 6000},
725 {"sensor3", 70, 7000},
726 }).Result()
727 if err != nil {
728 panic(err)
729 }
730
731 fmt.Println(res2) // >>> [10 20 30 40 50 60 70]
732
733 res3, err := rdb.TSRangeWithArgs(
734 ctx,
735 "sensor3",
736 10,
737 70,
738 &redis.TSRangeOptions{
739 Aggregator: redis.Min,
740 BucketDuration: 25,
741 },
742 ).Result()
743 if err != nil {
744 panic(err)
745 }
746
747 fmt.Println(res3) // >>> [{0 1000} {25 3000} {50 5000}]
748 // STEP_END
749
750 // STEP_START agg_align
751 res4, err := rdb.TSRangeWithArgs(
752 ctx,

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
TSCreateMethod · 0.65
TSMAddMethod · 0.65
TSRangeWithArgsMethod · 0.65

Tested by

no test coverage detected