diff options
| -rw-r--r-- | main.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -50,6 +50,17 @@ func handleGet(conn net.Conn, key string) { } } +func handleExists(conn net.Conn, key string){ + db.mu.Lock() + _, exists := db.data[key] + db.mu.Unlock() + if exists { + conn.Write([]byte(":1\r\n")) + } else { + conn.Write([]byte(":0\r\n")) + } +} + func handleSet(conn net.Conn, key, value string) { db.mu.Lock() db.data[key] = value @@ -115,6 +126,8 @@ func handleConnection(conn net.Conn) { handleGet(conn, args[1]) case command == "SET" && len(args) == 3: handleSet(conn, args[1], args[2]) + case command == "EXISTS" && len(args) == 2: + handleExists(conn, args[1]) default: conn.Write([]byte("-ERR unknown command or wrong arguments\r\n")) } |
