the driver).
0.21
* Change of char * to const char * for all key based functions.
+ * New MEMCACHED_CALLBACK_PREFIX_KEY added. You can now create domains for
+ values.
0.20 Mon May 5 08:34:26 PDT 2008
* New consistent distribution tests.
When memcached_delete() is called this function will be excuted. At the
point of its execution all connections have been closed.
+=item MEMCACHED_CALLBACK_PREFIX_KEY
+
+You can set a value which will be used to create a domain for your keys.
+The value specified here will be appended to each of your keys. The value can not
+be greater then MEMCACHED_PREFIX_KEY_MAX_SIZE and will reduce MEMCACHED_MAX_KEY by
+the value of your key. The prefix key is only applied to the primary key,
+not the master key.
+
=item MEMCACHED_CALLBACK_USER_DATA
This allows you to store a pointer to a specifc piece of data. This can be
new_clone->get_key_failure= ptr->get_key_failure;
new_clone->delete_trigger= ptr->delete_trigger;
+ if (ptr->prefix_key[0] != 0)
+ strcpy(new_clone->prefix_key, ptr->prefix_key);
+
rc= run_distribution(new_clone);
if (rc != MEMCACHED_SUCCESS)
{
memcached_realloc_function call_realloc;
memcached_trigger_key get_key_failure;
memcached_trigger_delete_key delete_trigger;
+ char prefix_key[MEMCACHED_PREFIX_KEY_MAX_SIZE];
+ size_t prefix_key_length;
#ifdef NOT_USED /* Future Use */
uint8_t replicas;
memcached_return warning;
server_key= memcached_generate_hash(ptr, key, key_length);
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %.*s %u\r\n", verb,
+ "%s %s%.*s %u\r\n", verb,
+ ptr->prefix_key,
(int)key_length, key,
offset);
unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
{
switch (flag)
{
+ case MEMCACHED_CALLBACK_PREFIX_KEY:
+ {
+ char *key= (char *)data;
+
+ if (key)
+ {
+ ptr->prefix_key_length= strlen(key);
+ if ((ptr->prefix_key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1)
+ || (strcpy(ptr->prefix_key, key) == NULL))
+ {
+ ptr->prefix_key_length= 0;
+ return MEMCACHED_BAD_KEY_PROVIDED;
+ }
+ }
+ else
+ {
+ memset(ptr->prefix_key, 0, MEMCACHED_PREFIX_KEY_MAX_SIZE);
+ ptr->prefix_key_length= 0;
+ }
+
+ break;
+ }
case MEMCACHED_CALLBACK_USER_DATA:
{
ptr->user_data= data;
switch (flag)
{
+ case MEMCACHED_CALLBACK_PREFIX_KEY:
+ {
+ *error= ptr->prefix_key[0] != 0 ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
+ return (void *)ptr->prefix_key;
+ }
case MEMCACHED_CALLBACK_USER_DATA:
{
*error= ptr->user_data ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE;
#define MEMCACHED_STRIDE 4
#define MEMCACHED_DEFAULT_TIMEOUT 1000
#define MEMCACHED_CONTINUUM_ADDITION 10 /* How many extra slots we should build for in the continuum */
+#define MEMCACHED_PREFIX_KEY_MAX_SIZE 12
typedef enum {
MEMCACHED_SUCCESS,
} memcached_behavior;
typedef enum {
+ MEMCACHED_CALLBACK_PREFIX_KEY,
MEMCACHED_CALLBACK_USER_DATA,
MEMCACHED_CALLBACK_CLEANUP_FUNCTION,
MEMCACHED_CALLBACK_CLONE_FUNCTION,
if (expiration)
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s %llu\r\n", (int)key_length, key,
+ "delete %s%.*s %llu\r\n",
+ ptr->prefix_key,
+ (int)key_length, key,
(unsigned long long)expiration);
else
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s\r\n", (int)key_length, key);
+ "delete %s%.*s\r\n",
+ ptr->prefix_key,
+ (int)key_length, key);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
{
size_t to_read;
char *value_ptr;
+ WATCHPOINT_ASSERT(ptr->root);
end_ptr= buffer + MEMCACHED_DEFAULT_COMMAND_SIZE;
memcached_result_reset(result);
/* We load the key */
{
char *key;
+ size_t prefix_length;
key= result->key;
result->key_length= 0;
- for (; isgraph(*string_ptr); string_ptr++)
+ for (prefix_length= ptr->root->prefix_key_length; isgraph(*string_ptr); string_ptr++)
{
- *key= *string_ptr;
- key++;
- result->key_length++;
+ if (prefix_length == 0)
+ {
+ *key= *string_ptr;
+ key++;
+ result->key_length++;
+ }
+ else
+ prefix_length--;
}
result->key[result->key_length]= 0;
}
WATCHPOINT_ASSERT(ptr->hosts[server_key].cursor_active == 1);
}
+ /* Only called when we have a prefix key */
+ if (ptr->prefix_key[0] != 0)
+ {
+ if ((memcached_io_write(&ptr->hosts[server_key], ptr->prefix_key, ptr->prefix_key_length, 0)) == -1)
+ {
+ memcached_server_response_reset(&ptr->hosts[server_key]);
+ rc= MEMCACHED_SOME_ERRORS;
+ continue;
+ }
+ }
+
if ((memcached_io_write(&ptr->hosts[server_key], keys[x], key_length[x], 0)) == -1)
{
memcached_server_response_reset(&ptr->hosts[server_key]);
if (cas)
write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %.*s %u %llu %zu %llu\r\n", storage_op_string(verb),
+ "%s %s%.*s %u %llu %zu %llu\r\n", storage_op_string(verb),
+ ptr->prefix_key,
(int)key_length, key, flags,
(unsigned long long)expiration, value_length,
(unsigned long long)cas);
else
write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %.*s %u %llu %zu\r\n", storage_op_string(verb),
+ "%s %s%.*s %u %llu %zu\r\n", storage_op_string(verb),
+ ptr->prefix_key,
(int)key_length, key, flags,
(unsigned long long)expiration, value_length);
return 0;
}
-memcached_return delete_trigger(memcached_st *ptr, char *key, size_t key_length)
+memcached_return delete_trigger(memcached_st *ptr, const char *key, size_t key_length)
{
assert(key);
return realloc(mem, size);
}
+memcached_return set_prefix(memcached_st *memc)
+{
+ memcached_return rc;
+ const char *key= "mine";
+ char *value;
+
+ /* Make sure be default none exists */
+ value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+ assert(rc == MEMCACHED_FAILURE);
+
+ /* Test a clean set */
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+ assert(memcmp(value, key, 4) == 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ /* Test that we can turn it off */
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+ assert(rc == MEMCACHED_FAILURE);
+
+ /* Now setup for main test */
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(memcmp(value, key, 4) == 0);
+
+ return MEMCACHED_SUCCESS;
+}
+
memcached_return set_memory_alloc(memcached_st *memc)
{
{
{"consistent", enable_consistent, 0, tests},
{"wheel", enable_wheel, 0, tests},
{"memory_allocators", set_memory_alloc, 0, tests},
+ {"prefix", set_prefix, 0, tests},
// {"udp", pre_udp, 0, tests},
{"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
{"string", 0, 0, string_tests},