flags, error);
}
+static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
+ const char *master_key,
+ size_t master_key_length,
+ const char **keys,
+ size_t *key_length,
+ size_t number_of_keys,
+ bool mget_mode);
+
char *memcached_get_by_key(memcached_st *ptr,
const char *master_key,
size_t master_key_length,
}
/* Request the key */
- *error= memcached_mget_by_key(ptr,
+ *error= memcached_mget_by_key_real(ptr,
master_key,
master_key_length,
- (const char **)&key, &key_length, 1);
+ (const char **)&key, &key_length, 1, false);
value= memcached_fetch(ptr, NULL, NULL,
value_length, flags, error);
unsigned int master_server_key,
bool is_master_key_set,
const char **keys, size_t *key_length,
- size_t number_of_keys);
+ size_t number_of_keys,
+ bool mget_mode);
-memcached_return memcached_mget_by_key(memcached_st *ptr,
+static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
const char *master_key,
size_t master_key_length,
const char **keys,
size_t *key_length,
- size_t number_of_keys)
+ size_t number_of_keys,
+ bool mget_mode)
{
unsigned int x;
memcached_return rc= MEMCACHED_NOTFOUND;
if (ptr->flags & MEM_BINARY_PROTOCOL)
return binary_mget_by_key(ptr, master_server_key, is_master_key_set, keys,
- key_length, number_of_keys);
+ key_length, number_of_keys, mget_mode);
if (ptr->flags & MEM_SUPPORT_CAS)
{
return rc;
}
+memcached_return memcached_mget_by_key(memcached_st *ptr,
+ const char *master_key,
+ size_t master_key_length,
+ const char **keys,
+ size_t *key_length,
+ size_t number_of_keys)
+{
+ return memcached_mget_by_key_real(ptr, master_key, master_key_length, keys,
+ key_length, number_of_keys, true);
+}
+
static memcached_return simple_binary_mget(memcached_st *ptr,
unsigned int master_server_key,
bool is_master_key_set,
const char **keys, size_t *key_length,
- size_t number_of_keys)
+ size_t number_of_keys, bool mget_mode)
{
memcached_return rc= MEMCACHED_NOTFOUND;
uint32_t x;
protocol_binary_request_getk request= {.bytes= {0}};
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
- if (number_of_keys == 1)
- request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
- else
+ if (mget_mode)
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ;
+ else
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
memcached_return vk;
vk= memcached_validate_key_length(key_length[x],
rc= MEMCACHED_SOME_ERRORS;
}
- if (number_of_keys > 1)
+ if (mget_mode)
{
/*
* Send a noop command to flush the buffers
static memcached_return replication_binary_mget(memcached_st *ptr,
uint32_t* hash, bool* dead_servers,
const char **keys, size_t *key_length,
- size_t number_of_keys)
+ size_t number_of_keys, bool mget_mode)
{
memcached_return rc= MEMCACHED_NOTFOUND;
uint32_t x;
protocol_binary_request_getk request= {.bytes= {0}};
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
- if (number_of_keys == 1)
- request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
- else
+ if (mget_mode)
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETKQ;
+ else
+ request.message.header.request.opcode= PROTOCOL_BINARY_CMD_GETK;
request.message.header.request.keylen= htons((uint16_t)key_length[x]);
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
memcached_server_response_increment(&ptr->hosts[server]);
}
- if (number_of_keys > 1)
+ if (mget_mode)
{
/*
* Send a noop command to flush the buffers
unsigned int master_server_key,
bool is_master_key_set,
const char **keys, size_t *key_length,
- size_t number_of_keys)
+ size_t number_of_keys, bool mget_mode)
{
memcached_return rc;
if (ptr->number_of_replicas == 0)
{
rc= simple_binary_mget(ptr, master_server_key, is_master_key_set,
- keys, key_length, number_of_keys);
+ keys, key_length, number_of_keys, mget_mode);
}
else
{
hash[x]= memcached_generate_hash(ptr, keys[x], key_length[x]);
rc= replication_binary_mget(ptr, hash, dead_servers, keys,
- key_length, number_of_keys);
+ key_length, number_of_keys, mget_mode);
ptr->call_free(ptr, hash);
ptr->call_free(ptr, dead_servers);
return TEST_SUCCESS;
}
+static test_return mget_end(memcached_st *memc)
+{
+ const char *keys[] = { "foo", "foo2" };
+ size_t lengths[] = { 3, 4 };
+ const char *values[] = { "fjord", "41" };
+
+ memcached_return rc;
+
+ // Set foo and foo2
+ for(int i = 0; i < 2; i++)
+ {
+ rc= memcached_set(memc, keys[i], lengths[i], values[i], strlen(values[i]),
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS);
+ }
+
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+
+ // retrieve both via mget
+ rc= memcached_mget(memc, keys, lengths, 2);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ char key[MEMCACHED_MAX_KEY];
+ size_t key_length;
+
+ // this should get both
+ for(int i = 0; i < 2; i++) {
+ string = memcached_fetch(memc, key, &key_length, &string_length,
+ &flags, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+ int val = 0;
+ if(key_length == 4)
+ val = 1;
+ assert(string_length == strlen(values[val]));
+ assert(strncmp(values[val], string, string_length) == 0);
+ free(string);
+ }
+
+ // this should indicate end
+ string = memcached_fetch(memc, key, &key_length, &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_END);
+
+ // now get just one
+ rc= memcached_mget(memc, keys, lengths, 1);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ string = memcached_fetch(memc, key, &key_length, &string_length, &flags, &rc);
+ assert(key_length == lengths[0]);
+ assert(strncmp(keys[0], key, key_length) == 0);
+ assert(string_length == strlen(values[0]));
+ assert(strncmp(values[0], string, string_length) == 0);
+ assert(rc == MEMCACHED_SUCCESS);
+ free(string);
+
+ // this should indicate end
+ string = memcached_fetch(memc, key, &key_length, &string_length, &flags, &rc);
+ assert(rc != MEMCACHED_SUCCESS);
+ assert(rc == MEMCACHED_END);
+
+ return TEST_SUCCESS;
+}
+
/* Do not copy the style of this code, I just access hosts to testthis function */
static test_return stats_servername_test(memcached_st *memc)
{
{"mget_result", 1, mget_result_test },
{"mget_result_alloc", 1, mget_result_alloc_test },
{"mget_result_function", 1, mget_result_function },
+ {"mget_end", 0, mget_end },
{"get_stats", 0, get_stats },
{"add_host_test", 0, add_host_test },
{"add_host_test_1", 0, add_host_test1 },