From f467d014a4590c8e35a4b60f889962833085e0ea Mon Sep 17 00:00:00 2001 From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:40:21 +0100 Subject: [PATCH] DOC-4323 added INCR command example (#3141) Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com> --- doctests/cmds_string_test.go | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 doctests/cmds_string_test.go diff --git a/doctests/cmds_string_test.go b/doctests/cmds_string_test.go new file mode 100644 index 00000000..fb7801a6 --- /dev/null +++ b/doctests/cmds_string_test.go @@ -0,0 +1,57 @@ +// EXAMPLE: cmds_string +// HIDE_START +package example_commands_test + +import ( + "context" + "fmt" + + "github.com/redis/go-redis/v9" +) + +// HIDE_END + +func ExampleClient_cmd_incr() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mykey") + // REMOVE_END + + // STEP_START incr + incrResult1, err := rdb.Set(ctx, "mykey", "10", 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(incrResult1) // >>> OK + + incrResult2, err := rdb.Incr(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(incrResult2) // >>> 11 + + incrResult3, err := rdb.Get(ctx, "mykey").Result() + + if err != nil { + panic(err) + } + + fmt.Println(incrResult3) // >>> 11 + // STEP_END + + // Output: + // OK + // 11 + // 11 +}