diff options
author | rsiddharth <s@ricketyspace.net> | 2019-11-02 11:05:54 -0400 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-04-17 20:56:34 -0400 |
commit | a89b692e370e65b0fb087a2f843faf9ce1d5a6ae (patch) | |
tree | 75f136112c75feefdc729c133d44185c925955d6 /nserver/src/protocol.c | |
parent | 64ab0153238cd3d06296cd31bd9bc09ba8545f33 (diff) |
nserver: protocol: Define ssdelete.
* nserver/src/protocol.c (ssdelete): New function.
* nserver/tests/protocol_tests.c (test_ssdelete): New test.
(all_tests): Add test_ssdelete.
Diffstat (limited to 'nserver/src/protocol.c')
-rw-r--r-- | nserver/src/protocol.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index 3c09733..adcfc21 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -37,6 +37,33 @@ int sscreate(char *key) return -1; } +int ssdelete(char *key) +{ + check(hash != NULL, "hash not initialized"); + + // 1. create bstring from 'key'. + bstring k = bfromcstr(key); + check(k != NULL, "key creation failed"); + + // 2. check if key exists. + Stats *st = (Stats *) Hashmap_get(hash, k); + if (st == NULL) { + // key does not exists. + return 0; + } + + // 3. delete key. + st = (Stats *) Hashmap_delete(hash, k); + check(st != NULL, "hash key delete failed"); + + // 4. clean up the stats for this key. + free(st); + + return 0; + error: + return -1; +} + int sssample(char *key, double s) { check(hash != NULL, "hash not initialized"); |