X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Flibmemcached%2Ftouch.cc;fp=src%2Flibmemcached%2Ftouch.cc;h=5c45ede1b0c596c9e441a6dbb984429c7c1e95c1;hb=d02c98cff56892d4c561aec87e4bec4a49e83051;hp=7213cbbe40664a36455698442a3bd15e01486ba3;hpb=c98c359a7ea03a0919a385bc88bf1387a47a41e8;p=m6w6%2Flibmemcached diff --git a/src/libmemcached/touch.cc b/src/libmemcached/touch.cc index 7213cbbe..5c45ede1 100644 --- a/src/libmemcached/touch.cc +++ b/src/libmemcached/touch.cc @@ -15,6 +15,29 @@ #include "libmemcached/common.h" +static memcached_return_t meta_touch(memcached_instance_st *instance, const char *key, size_t key_len, time_t expiration) { + char ex_buf[32] = " T"; + size_t ex_len = strlen(ex_buf); + + ex_len += snprintf(ex_buf + ex_len, sizeof(ex_buf) - ex_len, "%lu", (unsigned long) expiration); + + libmemcached_io_vector_st io_vec[] = { + {memcached_literal_param("mg ")}, + {memcached_array_string(instance->root->_namespace), + memcached_array_size(instance->root->_namespace)}, + {key, key_len}, + {ex_buf, ex_len}, + {memcached_literal_param("\r\n")} + }; + + memcached_return_t rc; + if (memcached_failed(rc = memcached_vdo(instance, io_vec, 5, true))) { + return memcached_set_error(*instance, MEMCACHED_WRITE_FAILURE, MEMCACHED_AT); + } + + return rc; +} + static memcached_return_t ascii_touch(memcached_instance_st *instance, const char *key, size_t key_length, time_t expiration) { char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH + 1]; @@ -98,8 +121,10 @@ memcached_return_t memcached_touch_by_key(memcached_st *shell, const char *group memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); memcached_instance_st *instance = memcached_instance_fetch(ptr, server_key); - if (ptr->flags.binary_protocol) { + if (memcached_is_binary(ptr)) { rc = binary_touch(instance, key, key_length, expiration); + } else if (memcached_is_meta(ptr)) { + rc = meta_touch(instance, key, key_length, expiration); } else { rc = ascii_touch(instance, key, key_length, expiration); }