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

Function ExampleClient_timeseries_compaction

doctests/timeseries_tut_test.go:987–1089  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

985}
986
987func ExampleClient_timeseries_compaction() {
988 ctx := context.Background()
989
990 rdb := redis.NewClient(&redis.Options{
991 Addr: "localhost:6379",
992 Password: "", // no password set
993 DB: 0, // use default DB
994 })
995
996 // REMOVE_START
997 // make sure we are working with fresh database
998 rdb.FlushDB(ctx)
999 rdb.Del(ctx, "hyg:1", "hyg:compacted")
1000 // REMOVE_END
1001
1002 // STEP_START create_compaction
1003 res45, err := rdb.TSCreate(ctx, "hyg:1").Result()
1004 if err != nil {
1005 panic(err)
1006 }
1007
1008 fmt.Println(res45) // >>> OK
1009
1010 res46, err := rdb.TSCreate(ctx, "hyg:compacted").Result()
1011 if err != nil {
1012 panic(err)
1013 }
1014
1015 fmt.Println(res46) // >>> OK
1016
1017 res47, err := rdb.TSCreateRule(
1018 ctx, "hyg:1", "hyg:compacted", redis.Min, 3,
1019 ).Result()
1020 if err != nil {
1021 panic(err)
1022 }
1023
1024 fmt.Println(res47) // >>> OK
1025
1026 res48, err := rdb.TSInfo(ctx, "hyg:1").Result()
1027 if err != nil {
1028 panic(err)
1029 }
1030
1031 fmt.Println(res48["rules"]) // >>> [[hyg:compacted 3 MIN 0]]
1032
1033 res49, err := rdb.TSInfo(ctx, "hyg:compacted").Result()
1034 if err != nil {
1035 panic(err)
1036 }
1037
1038 fmt.Println(res49["sourceKey"]) // >>> hyg:1
1039 // STEP_END
1040
1041 // STEP_START comp_add
1042 res50, err := rdb.TSMAdd(ctx, [][]interface{}{
1043 {"hyg:1", 0, 75},
1044 {"hyg:1", 1, 77},

Callers

nothing calls this directly

Calls 9

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
TSCreateMethod · 0.65
TSCreateRuleMethod · 0.65
TSInfoMethod · 0.65
TSMAddMethod · 0.65
TSRangeMethod · 0.65
TSAddMethod · 0.65

Tested by

no test coverage detected