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

Function ExampleClient_xdel

doctests/stream_tutorial_test.go:1039–1110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1037}
1038
1039func ExampleClient_xdel() {
1040 ctx := context.Background()
1041
1042 rdb := redis.NewClient(&redis.Options{
1043 Addr: "localhost:6379",
1044 Password: "", // no password docs
1045 DB: 0, // use default DB
1046 })
1047
1048 // REMOVE_START
1049 // start with fresh database
1050 rdb.FlushDB(ctx)
1051 rdb.Del(ctx, "race:italy")
1052 // REMOVE_END
1053
1054 _, err := rdb.XAdd(ctx, &redis.XAddArgs{
1055 Stream: "race:italy",
1056 MaxLen: 2,
1057 Values: map[string]interface{}{"rider": "Wood"},
1058 ID: "1692633198206-0",
1059 },
1060 ).Result()
1061
1062 if err != nil {
1063 panic(err)
1064 }
1065
1066 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
1067 Stream: "race:italy",
1068 MaxLen: 2,
1069 Values: map[string]interface{}{"rider": "Henshaw"},
1070 ID: "1692633208557-0",
1071 },
1072 ).Result()
1073
1074 if err != nil {
1075 panic(err)
1076 }
1077
1078 // STEP_START xdel
1079 res39, err := rdb.XRangeN(ctx, "race:italy", "-", "+", 2).Result()
1080
1081 if err != nil {
1082 panic(err)
1083 }
1084
1085 fmt.Println(res39)
1086 // >>> [{1692633198206-0 map[rider:Wood] 0 0} {1692633208557-0 map[rider:Henshaw] 0 0}]
1087
1088 res40, err := rdb.XDel(ctx, "race:italy", "1692633208557-0").Result()
1089
1090 if err != nil {
1091 panic(err)
1092 }
1093
1094 fmt.Println(res40) // 1
1095
1096 res41, err := rdb.XRangeN(ctx, "race:italy", "-", "+", 2).Result()

Callers

nothing calls this directly

Calls 6

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
XAddMethod · 0.65
XRangeNMethod · 0.65
XDelMethod · 0.65

Tested by

no test coverage detected