aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/main.go b/main.go
index 81ff1fc..38ccd34 100644
--- a/main.go
+++ b/main.go
@@ -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"))
}