From 9e0754d92f252f5946e51eb8472929fbb84fd684 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 4 Feb 2026 09:02:28 -0700 Subject: [PATCH] hashkey from inspecting raw --- src/adapt.go | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/adapt.go b/src/adapt.go index de24e6a..1c4dcac 100755 --- a/src/adapt.go +++ b/src/adapt.go @@ -8,30 +8,44 @@ import ( "io" "log" "net" + "regexp" "strconv" ) func adapt(ctx context.Context, config Config, conn net.Conn) error { reader := bufio.NewReader(conn) + alpha := regexp.MustCompile(`[a-zA-Z]`) + parts := regexp.MustCompile(`(.*?)\r\n*`) + for ctx.Err() == nil { if done, err := func() (bool, error) { - raw, message, err := readMessage(reader) + raw, err := readMessage(reader) if err != nil { if err == io.EOF { return true, nil } return true, err } - log.Printf("routing: %q (%+v)", raw, message) + log.Printf("routing: %q", raw) - if len(message) > 0 && message[0].(string) == "COMMAND" { - fmt.Fprintf(conn, "*0\r\n") - } else if len(raw) > 0 && len(message) > 0 { - hashKey := message[0].(string) - if len(message) > 1 { - hashKey = message[1].(string) + if len(raw) > 0 { + hashKey := "" + if matches := parts.FindAllSubmatch(raw, 5); len(matches) > 0 { + for i := range matches { + if isTheCommand := alpha.Match(matches[i][0]); isTheCommand { + for j := i + 1; j < len(matches); j++ { + if matches[j][0][0] == byte('$') { + continue + } + hashKey = string(matches[j][1]) + break + } + break + } + } } + log.Printf("hashkey %q", hashKey) if err := config.WithConn(hashKey, func(forwardConn net.Conn) error { //log.Printf("forwarding %q", raw)