Increment and decrement now works.
[awesomized/libmemcached] / lib / memcached_storage.c
index 40d36394234f024d892ddd1fff142cdc5c20aa4d..3df4913ad10fb23cb06d9b61a9c0ef4246bd3ec6 100644 (file)
@@ -19,16 +19,19 @@ static memcached_return memcached_send(memcached_st *ptr,
   size_t send_length;
   memcached_return rc;
   char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
+  unsigned int server_key;
 
   rc= memcached_connect(ptr);
 
   if (rc != MEMCACHED_SUCCESS)
     return rc;
 
+  server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
+
   send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 
                         "%s %.*s %u %u %u\r\n", verb,
                         key_length, key, flags, expiration, value_length);
-  if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
+  if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
   {
     fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
 
@@ -38,14 +41,14 @@ static memcached_return memcached_send(memcached_st *ptr,
   send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 
                         "%.*s\r\n", 
                         value_length, value);
-  if ((send(ptr->hosts[0].fd, buffer, send_length, 0) == -1))
+  if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
   {
     fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
 
     return MEMCACHED_WRITE_FAILURE;
   }
   
-  send_length= read(ptr->hosts[0].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
+  send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
 
   if (send_length && buffer[0] == 'S')  /* STORED */
     return MEMCACHED_SUCCESS;