Code for multi delete functions.
authorBrian Aker <brian@tangent.org>
Tue, 18 Dec 2007 09:12:49 +0000 (01:12 -0800)
committerBrian Aker <brian@tangent.org>
Tue, 18 Dec 2007 09:12:49 +0000 (01:12 -0800)
ChangeLog
include/memcached.h
lib/memcached_delete.c
lib/memcached_get.c
tests/function.c

index f364840d178bcd3e0fa897b2a46bd7be22fe4000..d2017cf4a1bd2cc35052221cc58689bc55a27e3e 100644 (file)
--- 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
index 8e90d6edb1d813746a31eb0c38ec72c4395fbc88..666e9e6b9898223d051fadbe75eeb1b2ce02cdb2 100644 (file)
@@ -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, 
index 519e52bec6fea58f6d304bf187d289f61559acec..4fe29421eb443f38318246a70a39091826a6ba07 100644 (file)
@@ -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;
+}
index b4266130e652f4baa2fb9b33e2ef6a825feecdcd..d0f4822b85953d98a8156dd6c8d00096109e8d62 100644 (file)
@@ -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;
index e717c3b8464592a79622b1647b2f3bf3b89efb61..ae2ec0324852523bf60ab3163fbc5315e48bc062 100644 (file)
@@ -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}
 };