Skip to content

Commit

Permalink
feat: update command prefix dynamically
Browse files Browse the repository at this point in the history
This is based on the number of commands sent from current connection.
  • Loading branch information
ryan-gang committed Jun 11, 2024
1 parent 5e242f8 commit 15bf11f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ import (

func defaultCallbacks(stageHarness *test_case_harness.TestCaseHarness, logPrefix string) resp_connection.RespConnectionCallbacks {
return resp_connection.RespConnectionCallbacks{
BeforeSendCommand: func(command string, args ...string) {
BeforeSendCommand: func(reusedConnection bool, command string, args ...string) {
var commandPrefix string
if reusedConnection {
commandPrefix = ">"
} else {
commandPrefix = "$ redis-cli"
}

if len(args) > 0 {
stageHarness.Logger.Infof("%s$ redis-cli %s %s", logPrefix, command, strings.Join(args, " "))
stageHarness.Logger.Infof("%s%s %s %s", logPrefix, commandPrefix, command, strings.Join(args, " "))
} else {
stageHarness.Logger.Infof("%s$ redis-cli %s", logPrefix, command)
stageHarness.Logger.Infof("%s%s %s", logPrefix, commandPrefix, command)
}
},
BeforeSendValue: func(value resp_value.Value) {
Expand Down
7 changes: 5 additions & 2 deletions internal/resp/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

// BeforeSendValue is called when a value is sent using SendValue.
// It is NOT called when using SendCommand
Expand Down Expand Up @@ -83,7 +83,10 @@ func (c *RespConnection) Close() error {

func (c *RespConnection) SendCommand(command string, args ...string) error {
if c.Callbacks.BeforeSendCommand != nil {
c.Callbacks.BeforeSendCommand(command, args...)
if c.SentBytes > 0 {
c.Callbacks.BeforeSendCommand(true, command, args...)
}
c.Callbacks.BeforeSendCommand(false, command, args...)
}

encodedValue := resp_encoder.Encode(resp_value.NewStringArrayValue(append([]string{command}, args...)))
Expand Down

0 comments on commit 15bf11f

Please sign in to comment.