Skip to content

DOC-4439 auth command examples #3236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions doctests/cmds_cnxmgmt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// EXAMPLE: cmds_cnxmgmt
// HIDE_START
package example_commands_test

import (
"context"
"fmt"

"github.com/redis/go-redis/v9"
)

// HIDE_END

func ExampleClient_cmd_auth() {
ctx := context.Background()

rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
})
// REMOVE_START

// REMOVE_END
// STEP_START auth1
// REMOVE_START
rdb.ConfigSet(ctx, "requirepass", "temp_pass")
// REMOVE_END
authResult1, err := rdb.Conn().Auth(ctx, "temp_pass").Result()

if err != nil {
panic(err)
}

fmt.Println(authResult1) // >>> OK

authResult2, err := rdb.Conn().AuthACL(
ctx, "default", "temp_pass",
).Result()

if err != nil {
panic(err)
}

fmt.Println(authResult2) // >>> OK
// REMOVE_START
confRes, err := rdb.ConfigSet(ctx, "requirepass", "").Result()
fmt.Println(confRes)
// REMOVE_END
// STEP_END

// STEP_START auth2
// REMOVE_START
res, err := rdb.ACLSetUser(ctx, "test-user", "on", ">strong_password", "+acl").Result()
fmt.Println(res)
// REMOVE_END
authResult3, err := rdb.Conn().AuthACL(ctx,
"test-user", "strong_password",
).Result()

if err != nil {
panic(err)
}

fmt.Println(authResult3) // >>> OK
// REMOVE_START
rdb.ACLDelUser(ctx, "test-user")
// REMOVE_END
// STEP_END

// Output:
// OK
// OK
// OK
}
Loading