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

CC-1292: Update log prefix dynamically when reusing connection #152

Merged
merged 3 commits into from
Jun 12, 2024

Conversation

ryan-gang
Copy link
Contributor

This pull request updates the BeforeSendCommand callback in the RespConnectionCallbacks struct to include a new parameter reusedConnection which indicates whether the connection is being reused or not. The BeforeSendCommand callback is used to log the commands being sent to the server. With this change, the command prefix is dynamically set based on whether the connection is being reused or not. If the connection is reused, the command prefix is set to ">", otherwise it is set to "$ redis-cli". This provides more context in the logs when commands are being sent.

Copy link

linear bot commented Jun 11, 2024

@ryan-gang ryan-gang self-assigned this Jun 11, 2024
Copy link
Contributor Author

@ryan-gang ryan-gang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -14,7 +14,7 @@ import (
type RespConnectionCallbacks struct {
// BeforeSendCommand is called when a command is sent to the server.
// This can be useful for info logs.
BeforeSendCommand func(command string, args ...string)
BeforeSendCommand func(reusedConnection bool, command string, args ...string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal since we only have this one use-case, but wanted to leave a note:

A common pattern I've seen for cases like these is to pass in RespConnection itself to the callback - that way the callback has access to everything public on RespConnection, and it helps avoid parameters like reusedConnection which are use-case specific (over time we might have to add new parameters for multiple things that could just be computed off of RespConnection)

@ryan-gang ryan-gang merged commit 7d9020c into main Jun 12, 2024
2 checks passed
@ryan-gang ryan-gang deleted the CC-1292 branch June 12, 2024 07:38
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 this pull request may close these issues.

2 participants