Skip to content
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

Allow setting client name with paramater in connection string #2312

Closed
sylr opened this issue Dec 15, 2022 · 5 comments · Fixed by #2333
Closed

Allow setting client name with paramater in connection string #2312

sylr opened this issue Dec 15, 2022 · 5 comments · Fixed by #2333

Comments

@sylr
Copy link
Contributor

sylr commented Dec 15, 2022

Expected Behavior

Connection string should allow setting the client name as the C# client does (see ClientName).

Current Behavior

go-redis does not allow client name in connection string.

Possible Solution

rediss://<user>:<password>@<host>:<port>/[<db>]?[name=<client_name>]
@monkey92t
Copy link
Collaborator

func ExampleParseURL() {
	opt, err := redis.ParseURL("redis://:qwerty@localhost:6379/1?dial_timeout=5s")
	if err != nil {
		panic(err)
	}
	fmt.Println("addr is", opt.Addr)
	fmt.Println("db is", opt.DB)
	fmt.Println("password is", opt.Password)
	fmt.Println("dial timeout is", opt.DialTimeout)

	// Create client as usually.
	_ = redis.NewClient(opt)

	// Output: addr is localhost:6379
	// db is 1
	// password is qwerty
	// dial timeout is 5s
}


func ParseURL(redisURL string) (*Options, error) {
	u, err := url.Parse(redisURL)
	if err != nil {
		return nil, err
	}

	switch u.Scheme {
	case "redis", "rediss":
		return setupTCPConn(u)
	case "unix":
		return setupUnixConn(u)
	default:
		return nil, fmt.Errorf("redis: invalid URL scheme: %s", u.Scheme)
	}
}

@sylr
Copy link
Contributor Author

sylr commented Dec 16, 2022

@monkey92t could you elaborate what you mean with this example ?

@monkey92t
Copy link
Collaborator

monkey92t commented Dec 16, 2022

Oh, sorry, I misread your issue... please forgive me😁...

Redis ClientName https://redis.io/commands/client-setname/ is the name of the network connection, so it doesn't make sense for go-redis...

@ash2k
Copy link
Contributor

ash2k commented Dec 19, 2022

Why does it not make sense? I'd like to be able to see the list of clients, connected to redis using CLIENT LIST. My application needs to set the client name for that. There is ClientSetName() method on some connection types but it's impractical and wasteful to call it before each transaction/operation.

An ideal solution would be to allow to specify client name in Options/FailoverOptions/etc and let the library execute the CLIENT SETNAME command once right after a connection is established.

@monkey92t
Copy link
Collaborator

Why does it not make sense? I'd like to be able to see the list of clients, connected to redis using CLIENT LIST. My application needs to set the client name for that. There is ClientSetName() method on some connection types but it's impractical and wasteful to call it before each transaction/operation.

looks great

@monkey92t monkey92t reopened this Dec 19, 2022
@monkey92t monkey92t linked a pull request Dec 28, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants