From 723918391bcec3248c5e7c32d439c4301aa8765f Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Tue, 23 Jul 2013 13:47:34 -0400 Subject: [PATCH] add delete command back in --- src/handlers.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/handlers.c b/src/handlers.c index 067803c..f8d1589 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -14,7 +14,8 @@ const char* HELP_TEXT = "COMMANDS:\r\n" " STATS - show statistics\r\n" " GET - get from the cache or empty when not present\r\n" - " VERSION - show the current application version" + " DELETE - remove the entry from the cache if it exists\r\n" + " VERSION - show the current application version\r\n" " FLUSH_ALL - clear the cache\r\n" " HELP - show this message\r\n" " QUIT - disconnect from the server\r\n"; @@ -62,6 +63,22 @@ void handle_flush(KCLIST* tokens, FILE* client){ } } +void handle_delete(KCLIST* tokens, FILE* client){ + if(kclistcount(tokens)){ + char* key; + list_shift(tokens, &key); + if(key == NULL){ + return; + } + if(kcdbremove(db, key, strlen(key))){ + fputs("DELETED\r\n", client); + } else{ + fputs("NOT_FOUND\r\n", client); + } + } else{ + fputs("INVALID DELETE COMMAND: DELETE \r\n", client); + } +} void handle_get(KCLIST* tokens, FILE* client){ if(kclistcount(tokens)){ @@ -128,6 +145,8 @@ int handle_command(char* buffer, FILE* client){ handle_get(tokens, client); } else if(strcmp(command, "stats") == 0){ handle_stats(tokens, client); + } else if(strcmp(command, "delete") == 0){ + handle_delete(tokens, client); } else if(strcmp(command, "flush_all") == 0){ handle_flush(tokens, client); } else if(strcmp(command, "version") == 0){