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

Function ExampleClient_racefrance2

doctests/stream_tutorial_test.go:309–477  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

307}
308
309func ExampleClient_racefrance2() {
310 ctx := context.Background()
311
312 rdb := redis.NewClient(&redis.Options{
313 Addr: "localhost:6379",
314 Password: "", // no password docs
315 DB: 0, // use default DB
316 })
317
318 // REMOVE_START
319 // start with fresh database
320 rdb.FlushDB(ctx)
321 rdb.Del(ctx, "race:france")
322 // REMOVE_END
323
324 _, err := rdb.XAdd(ctx, &redis.XAddArgs{
325 Stream: "race:france",
326 Values: map[string]interface{}{
327 "rider": "Castilla",
328 "speed": 30.2,
329 "position": 1,
330 "location_id": 1,
331 },
332 ID: "1692632086370-0",
333 }).Result()
334
335 if err != nil {
336 panic(err)
337 }
338
339 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
340 Stream: "race:france",
341 Values: map[string]interface{}{
342 "rider": "Norem",
343 "speed": 28.8,
344 "position": 3,
345 "location_id": 1,
346 },
347 ID: "1692632094485-0",
348 }).Result()
349
350 if err != nil {
351 panic(err)
352 }
353
354 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
355 Stream: "race:france",
356 Values: map[string]interface{}{
357 "rider": "Prickett",
358 "speed": 29.7,
359 "position": 2,
360 "location_id": 1,
361 },
362 ID: "1692632102976-0",
363 }).Result()
364
365 if err != nil {
366 panic(err)

Callers

nothing calls this directly

Calls 8

FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
XAddMethod · 0.65
XRangeMethod · 0.65
XRangeNMethod · 0.65
XRevRangeNMethod · 0.65
XReadMethod · 0.65

Tested by

no test coverage detected