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

Function ExampleClient_rule2

doctests/list_tutorial_test.go:627–697  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

625}
626
627func ExampleClient_rule2() {
628 ctx := context.Background()
629
630 rdb := redis.NewClient(&redis.Options{
631 Addr: "localhost:6379",
632 Password: "", // no password docs
633 DB: 0, // use default DB
634 })
635
636 // REMOVE_START
637 rdb.Del(ctx, "bikes:repairs")
638 // REMOVE_END
639
640 // STEP_START rule_2
641 res42, err := rdb.LPush(ctx, "bikes:repairs", "bike:1", "bike:2", "bike:3").Result()
642
643 if err != nil {
644 panic(err)
645 }
646
647 fmt.Println(res42) // >>> 3
648
649 res43, err := rdb.Exists(ctx, "bikes:repairs").Result()
650
651 if err != nil {
652 panic(err)
653 }
654
655 fmt.Println(res43) // >>> 1
656
657 res44, err := rdb.LPop(ctx, "bikes:repairs").Result()
658
659 if err != nil {
660 panic(err)
661 }
662
663 fmt.Println(res44) // >>> bike:3
664
665 res45, err := rdb.LPop(ctx, "bikes:repairs").Result()
666
667 if err != nil {
668 panic(err)
669 }
670
671 fmt.Println(res45) // >>> bike:2
672
673 res46, err := rdb.LPop(ctx, "bikes:repairs").Result()
674
675 if err != nil {
676 panic(err)
677 }
678
679 fmt.Println(res46) // >>> bike:1
680
681 res47, err := rdb.Exists(ctx, "bikes:repairs").Result()
682
683 if err != nil {
684 panic(err)

Callers

nothing calls this directly

Calls 5

DelMethod · 0.65
ResultMethod · 0.65
LPushMethod · 0.65
ExistsMethod · 0.65
LPopMethod · 0.65

Tested by

no test coverage detected