aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-12 15:00:16 +0200
committeralex <[email protected]>2026-07-12 15:00:16 +0200
commit6cb3313793bf45e197b3048f0abd2f600bf97bb5 (patch)
tree019a0995c7f9422ec9d739c77379ee7cc1a96b9c /main.go
parentce9d9f8b2183bc0a31bfa40e780ae07182bc7cf8 (diff)
downloadredis-clone-6cb3313793bf45e197b3048f0abd2f600bf97bb5.tar.xz
redis-clone-6cb3313793bf45e197b3048f0abd2f600bf97bb5.zip
multi exec and discardmulti/execute
Diffstat (limited to 'main.go')
-rw-r--r--main.go18
1 files changed, 13 insertions, 5 deletions
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