From: Brian Aker Date: Tue, 18 Dec 2007 09:12:49 +0000 (-0800) Subject: Code for multi delete functions. X-Git-Tag: 0.13~21 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0f665e1d72ff2466dae6de01331b2cfb5a4d3caa;p=m6w6%2Flibmemcached Code for multi delete functions. --- diff --git a/ChangeLog b/ChangeLog index f364840d..d2017cf4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ protocol was wrong. * Lingering socket fixes for FreeBSD. * Patches from Kevin Dalley for FreeBSD 4.0 + * Added multi delete functions. 0.12 Tue Dec 11 15:20:55 PST 2007 * Updates for consistent hashing diff --git a/include/memcached.h b/include/memcached.h index 8e90d6ed..666e9e6b 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -362,6 +362,17 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, char *key, size_t key_length, time_t expiration); +memcached_return memcached_mdelete(memcached_st *ptr, + char **key, size_t *key_length, + unsigned int number_of_keys, + time_t expiration); + +memcached_return memcached_mdelete_by_key(memcached_st *ptr, + char *master_key, size_t master_key_length, + char **key, size_t *key_length, + unsigned int number_of_keys, + time_t expiration); + /* Result Struct */ void memcached_result_free(memcached_result_st *result); memcached_result_st *memcached_result_create(memcached_st *ptr, diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index 519e52be..4fe29421 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -66,3 +66,70 @@ error: LIBMEMCACHED_MEMCACHED_DELETE_END(); return rc; } + +memcached_return memcached_mdelete(memcached_st *ptr, + char **key, size_t *key_length, + unsigned int number_of_keys, + time_t expiration) +{ + return memcached_mdelete_by_key(ptr, NULL, 0, + key, key_length, + number_of_keys, expiration); + +} + +memcached_return memcached_mdelete_by_key(memcached_st *ptr, + char *master_key, size_t master_key_length, + char **key, size_t *key_length, + unsigned int number_of_keys, + time_t expiration) +{ + size_t send_length; + memcached_return rc= MEMCACHED_SUCCESS; + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; + unsigned int master_server_key= 0; + unsigned int x; + + LIBMEMCACHED_MEMCACHED_DELETE_START(); + + if (ptr->hosts == NULL || ptr->number_of_hosts == 0) + return MEMCACHED_NO_SERVERS; + + if (master_key && master_key_length) + master_server_key= memcached_generate_hash(ptr, master_key, master_key_length); + + for (x= 0; x < number_of_keys; x++) + { + unsigned int server_key; + + if (master_key && master_key_length) + server_key= master_server_key; + else + server_key= memcached_generate_hash(ptr, key[x], key_length[x]); + + if (expiration) + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "delete %.*s %llu\r\n", (int)(key_length[x]), key[x], + (unsigned long long)expiration); + else + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "delete %.*s\r\n", (int)(key_length[x]), key[x]); + + (void)memcached_do(ptr, server_key, buffer, send_length, 0); + } + + for (x= 0; x < ptr->number_of_hosts; x++) + { + if (memcached_server_response_count(ptr, x)) + { + /* We need to do something about non-connnected hosts in the future */ + if ((memcached_io_write(ptr, x, NULL, 0, 1)) == -1) + { + rc= MEMCACHED_SOME_ERRORS; + } + } + } + + LIBMEMCACHED_MEMCACHED_DELETE_END(); + return rc; +} diff --git a/lib/memcached_get.c b/lib/memcached_get.c index b4266130..d0f4822b 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -120,6 +120,9 @@ memcached_return memcached_mget_by_key(memcached_st *ptr, { rc= memcached_connect(ptr, server_key); + if (rc != MEMCACHED_SUCCESS) + continue; + if ((memcached_io_write(ptr, server_key, get_command, get_command_length, 0)) == -1) { rc= MEMCACHED_SOME_ERRORS; diff --git a/tests/function.c b/tests/function.c index e717c3b8..ae2ec032 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1703,6 +1703,28 @@ uint8_t mget_read_result(memcached_st *memc) return 0; } +uint8_t delete_generate(memcached_st *memc) +{ + unsigned int x; + + for (x= 0; x < GLOBAL_COUNT; x++) + { + (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); + } + + return 0; +} + +uint8_t mdelete_generate(memcached_st *memc) +{ + memcached_return rc; + + rc= memcached_mdelete(memc, global_keys, global_keys_length, GLOBAL_COUNT, 0); + + return 0; +} + + uint8_t free_data(memcached_st *memc) { pairs_free(global_pairs); @@ -1998,6 +2020,8 @@ test_st generate_tests[] ={ {"get_read", 0, get_read }, {"mget_read", 0, mget_read }, {"mget_read_result", 0, mget_read_result }, + {"mdelete_generate", 0, mdelete_generate }, + {"delete_generate", 0, delete_generate }, {"cleanup", 0, cleanup_pairs }, {0, 0, 0} };