Skip to content

Commit

Permalink
DOC-4323 added INCR command example (#3141)
Browse files Browse the repository at this point in the history
Co-authored-by: ofekshenawa <[email protected]>
  • Loading branch information
andy-stark-redis and ofekshenawa authored Oct 9, 2024
1 parent 0c84b62 commit f467d01
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions doctests/cmds_string_test.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f467d01

Please sign in to comment.