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

newClient should panic when failed to connect to a db #3080

Open
cruvie opened this issue Aug 5, 2024 · 2 comments
Open

newClient should panic when failed to connect to a db #3080

cruvie opened this issue Aug 5, 2024 · 2 comments

Comments

@cruvie
Copy link

cruvie commented Aug 5, 2024

Issue tracker is used for reporting bugs and discussing new features. Please use
stackoverflow for supporting issues.

newClient should panic when failed to connect to a db

Expected Behavior

panic when failed to connect to a db

Current Behavior

nothing happened

Possible Solution

panic when failed to connect to a db

Steps to Reproduce

	client := redis.NewClient(&redis.Options{
		Addr:     "127.0.0.1:7923",
		Password: "123456",
		DB:       0,
	})
	if client == nil {
		t.Error("client is nil")
	}

Context (Environment)

it leaves init error to runtime error

newClient should panic when failed to connect to a db

Detailed Description

Possible Implementation

@LINKIWI
Copy link
Contributor

LINKIWI commented Aug 17, 2024

Panicking on initialization due to a single connection error would be extremely weird behavior. go-redis establishes connections lazily on-demand when commands are issued, and any connection errors are correctly surfaced there. If you want to ensure that a connection is valid after creating a client, consider issuing a Ping immediately, and panicking at your application layer if that fails.

@Kamalesh-Seervi
Copy link

can I work on this

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

No branches or pull requests

3 participants