libmemcached中的memcached_get()问题 [英] question with memcached_get() in libmemcached
问题描述
memcached_get (memcached_st *ptr,
const char *key, size_t key_length,
size_t *value_length,
uint32_t *flags,
memcached_return_t *error);
为什么需要在此处传递参数"size_t key_length"和"size_t * value_length"?我认为可以直接通过键获取值.
Why need to pass the params "size_t key_length" and "size_t *value_length" here ? I think the value can be fetched by key directly.
谁能帮助告诉我原因,谢谢.
who can help to tell me the reason, thanks.
推荐答案
key参数是指向要从内存缓存中获取信息的标识符的指针. key_length告诉memcached_get()函数您的标识符数据有多长时间.
The key parameter is a pointer to an identifier for the information you want to get from memcache. The key_length tells the memcached_get() function how long your identifier data is.
如果libmemcache API假定key参数所指向的数据是一个以NULL终止的字符串,那么我们就不需要传递key_length参数.但是通过不做这样的假设,API允许我们使用除以NULL终止的char字符串之外的其他数据作为键(例如,UTF-16字符串或二进制数字).
If the libmemcache API assumed that the data pointed to by the key parameter was a NULL-terminated string of characters, then we wouldn't need to also pass in the key_length parameter. But by not making that assumption the API allows us to use data other than NULL-terminated char strings as keys (for example, UTF-16 strings, or binary numbers).
这篇关于libmemcached中的memcached_get()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!