From 6cb3313793bf45e197b3048f0abd2f600bf97bb5 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 12 Jul 2026 15:00:16 +0200 Subject: multi exec and discard --- main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 36a41b5..ebf8a08 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,7 @@ func handleConnection(conn net.Conn) { conn.Close() }() fmt.Println("Client connected:", conn.RemoteAddr()) + session := commands.NewClientSession() // <-- Create connection session reader := bufio.NewReader(conn) for { @@ -84,15 +85,22 @@ func handleConnection(conn net.Conn) { fmt.Printf("Parsed RESP Arguments: %v\n", args) - command := strings.ToUpper(args[0]) + args[0] = strings.ToUpper(args[0]) + commandName := args[0] - if cmd , ok := commands.PubSubRegistry[command]; ok { + if cmd, ok := commands.SessionRegistry[commandName]; ok { + commands.DispatchSession(db,conn, session, cmd, args) + } else if cmd, ok := commands.PubSubRegistry[commandName]; ok { commands.DispatchPubSub(conn, &hub, cmd, args) - } else if cmd, ok := commands.BaseRegistry[command]; ok { + } else if cmd, ok := commands.BaseRegistry[commandName]; ok { + if session.InTransaction { + commands.QueueBaseCommand(conn, session, args, cmd.MinArgs) + } else { res := commands.DispatchBaseCommand(db, cmd, args) conn.Write(core.SerializeRESP(res)) + } } else { - conn.Write(core.SerializeRESP(fmt.Errorf("ERR unknown command '%s'", command))) - } + conn.Write(core.SerializeRESP(fmt.Errorf("-ERR unknown command '%s'", commandName))) +} } } \ No newline at end of file -- cgit v1.2.3