diff options
| author | alex <[email protected]> | 2026-07-06 13:55:11 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-06 13:55:11 +0200 |
| commit | 6745833aba4799104f299704af261696ce82b291 (patch) | |
| tree | 9f9d9995c826602211446e181b397461d18593e8 /main.go | |
| parent | f00398f4be24b5c3cce52c36dc71a42d1d0ccfbe (diff) | |
| download | redis-clone-6745833aba4799104f299704af261696ce82b291.tar.xz redis-clone-6745833aba4799104f299704af261696ce82b291.zip | |
refactored all handlers to take all args as a parameter
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 25 |
1 files changed, 9 insertions, 16 deletions
@@ -5,7 +5,6 @@ import ( "fmt" "net" "os" - "strconv" "strings" ) @@ -55,31 +54,25 @@ func handleConnection(conn net.Conn) { switch { case command == "GET" && len(args) == 2: - handleGet(conn, args[1]) + handleGet(conn, args) case command == "SET" && len(args) == 3: - handleSet(conn, args[1], args[2]) + handleSet(conn, args) case command == "EXISTS" && len(args) == 2: - handleExists(conn, args[1]) + handleExists(conn, args) case command == "DEL" && len(args) == 2: - handleDel(conn, args[1]) + handleDel(conn, args) case command == "INCR" && len(args) == 2: - handleIncr(conn, args[1]) + handleIncr(conn, args) case command == "DECR" && len(args) == 2: - handleDecr(conn, args[1]) + handleDecr(conn, args) case command == "PING" && len(args) == 1: - handlePing(conn) + handlePing(conn, args) case command == "FLUSHALL" && len(args) == 1: - handleFlushall(conn) + handleFlushall(conn, args) case command == "RPUSH" && len(args) >= 3: handleRpush(conn, args) case command == "LRANGE" && len(args) == 4: - start, err1 := strconv.Atoi(args[2]) - stop, err2 := strconv.Atoi(args[3]) - if err1 != nil || err2 != nil { - conn.Write([]byte("-ERR value is not an integer or out of range\r\n")) - break - } - handleLrange(conn, args[1], start, stop) + handleLrange(conn, args) default: conn.Write([]byte("-ERR unknown command or wrong arguments\r\n")) } |
