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