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

Function ExampleClient_racefrance1

doctests/stream_tutorial_test.go:100–222  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98}
99
100func ExampleClient_racefrance1() {
101 ctx := context.Background()
102
103 rdb := redis.NewClient(&redis.Options{
104 Addr: "localhost:6379",
105 Password: "", // no password docs
106 DB: 0, // use default DB
107 })
108
109 // REMOVE_START
110 // start with fresh database
111 rdb.FlushDB(ctx)
112 rdb.Del(ctx, "race:france")
113 // REMOVE_END
114
115 _, err := rdb.XAdd(ctx, &redis.XAddArgs{
116 Stream: "race:france",
117 Values: map[string]interface{}{
118 "rider": "Castilla",
119 "speed": 30.2,
120 "position": 1,
121 "location_id": 1,
122 },
123 ID: "1692632086370-0",
124 }).Result()
125
126 if err != nil {
127 panic(err)
128 }
129
130 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
131 Stream: "race:france",
132 Values: map[string]interface{}{
133 "rider": "Norem",
134 "speed": 28.8,
135 "position": 3,
136 "location_id": 1,
137 },
138 ID: "1692632094485-0",
139 }).Result()
140
141 if err != nil {
142 panic(err)
143 }
144
145 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
146 Stream: "race:france",
147 Values: map[string]interface{}{
148 "rider": "Prickett",
149 "speed": 29.7,
150 "position": 2,
151 "location_id": 1,
152 },
153 ID: "1692632102976-0",
154 }).Result()
155
156 if err != nil {
157 panic(err)

Callers

nothing calls this directly

Calls 8

UNUSEDFunction · 0.85
FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
XAddMethod · 0.65
XRangeNMethod · 0.65
XReadMethod · 0.65
XLenMethod · 0.65

Tested by

no test coverage detected