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

Function ExampleClient_timeseries_delete

doctests/timeseries_tut_test.go:1091–1183  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1089}
1090
1091func ExampleClient_timeseries_delete() {
1092 ctx := context.Background()
1093
1094 rdb := redis.NewClient(&redis.Options{
1095 Addr: "localhost:6379",
1096 Password: "", // no password set
1097 DB: 0, // use default DB
1098 })
1099
1100 // REMOVE_START
1101 // make sure we are working with fresh database
1102 rdb.FlushDB(ctx)
1103 rdb.Del(ctx, "thermometer:1")
1104 // Setup initial data
1105 rdb.TSCreate(ctx, "thermometer:1")
1106 rdb.TSMAdd(ctx, [][]interface{}{
1107 {"thermometer:1", 1, 9.2},
1108 {"thermometer:1", 2, 9.9},
1109 })
1110 // REMOVE_END
1111
1112 // STEP_START del
1113 res54, err := rdb.TSInfo(ctx, "thermometer:1").Result()
1114 if err != nil {
1115 panic(err)
1116 }
1117
1118 fmt.Println(res54["totalSamples"]) // >>> 2
1119 fmt.Println(res54["firstTimestamp"]) // >>> 1
1120 fmt.Println(res54["lastTimestamp"]) // >>> 2
1121
1122 res55, err := rdb.TSAdd(ctx, "thermometer:1", 3, 9.7).Result()
1123 if err != nil {
1124 panic(err)
1125 }
1126
1127 fmt.Println(res55) // >>> 3
1128
1129 res56, err := rdb.TSInfo(ctx, "thermometer:1").Result()
1130 if err != nil {
1131 panic(err)
1132 }
1133
1134 fmt.Println(res56["totalSamples"]) // >>> 3
1135 fmt.Println(res56["firstTimestamp"]) // >>> 1
1136 fmt.Println(res56["lastTimestamp"]) // >>> 3
1137
1138 res57, err := rdb.TSDel(ctx, "thermometer:1", 1, 2).Result()
1139 if err != nil {
1140 panic(err)
1141 }
1142
1143 fmt.Println(res57) // >>> 2
1144
1145 res58, err := rdb.TSInfo(ctx, "thermometer:1").Result()
1146 if err != nil {
1147 panic(err)
1148 }

Callers

nothing calls this directly

Calls 8

FlushDBMethod · 0.65
DelMethod · 0.65
TSCreateMethod · 0.65
TSMAddMethod · 0.65
ResultMethod · 0.65
TSInfoMethod · 0.65
TSAddMethod · 0.65
TSDelMethod · 0.65

Tested by

no test coverage detected