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

Function ExampleClient_xgroupread

doctests/stream_tutorial_test.go:554–659  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

552}
553
554func ExampleClient_xgroupread() {
555 ctx := context.Background()
556
557 rdb := redis.NewClient(&redis.Options{
558 Addr: "localhost:6379",
559 Password: "", // no password docs
560 DB: 0, // use default DB
561 })
562
563 // REMOVE_START
564 // start with fresh database
565 rdb.FlushDB(ctx)
566 rdb.Del(ctx, "race:italy")
567 // REMOVE_END
568
569 _, err := rdb.XGroupCreateMkStream(ctx,
570 "race:italy", "italy_riders", "$",
571 ).Result()
572
573 if err != nil {
574 panic(err)
575 }
576
577 // STEP_START xgroup_read
578 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
579 Stream: "race:italy",
580 Values: map[string]interface{}{"rider": "Castilla"},
581 }).Result()
582 // >>> 1692632639151-0
583
584 if err != nil {
585 panic(err)
586 }
587
588 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
589 Stream: "race:italy",
590 Values: map[string]interface{}{"rider": "Royce"},
591 }).Result()
592 // >>> 1692632647899-0
593
594 if err != nil {
595 panic(err)
596 }
597
598 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
599 Stream: "race:italy",
600 Values: map[string]interface{}{"rider": "Sam-Bodden"},
601 }).Result()
602 // >>> 1692632662819-0
603
604 if err != nil {
605 panic(err)
606 }
607
608 _, err = rdb.XAdd(ctx, &redis.XAddArgs{
609 Stream: "race:italy",
610 Values: map[string]interface{}{"rider": "Prickett"},
611 }).Result()

Callers

nothing calls this directly

Calls 8

UNUSEDFunction · 0.85
FlushDBMethod · 0.65
DelMethod · 0.65
ResultMethod · 0.65
XGroupCreateMkStreamMethod · 0.65
XAddMethod · 0.65
XReadGroupMethod · 0.65
XLenMethod · 0.65

Tested by

no test coverage detected