diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -67,6 +67,20 @@ func handleSet(conn net.Conn, key, value string) { db.mu.Unlock() conn.Write([]byte("+OK\r\n")) } + +func handleDel(conn net.Conn, key string){ + db.mu.Lock() + _, exists := db.data[key] + + if exists { + delete(db.data, key) + conn.Write([]byte(":1\r\n")) + } else { + conn.Write([]byte(":0\r\n")) + } + db.mu.Unlock() +} + func parseRESP(reader *bufio.Reader) ([]string, error) { line, err := reader.ReadString('\n') if err != nil { @@ -128,6 +142,8 @@ func handleConnection(conn net.Conn) { handleSet(conn, args[1], args[2]) case command == "EXISTS" && len(args) == 2: handleExists(conn, args[1]) + case command == "DEL" && len(args) == 2: + handleDel(conn, args[1]) default: conn.Write([]byte("-ERR unknown command or wrong arguments\r\n")) } |
