question with memcached_get() in libmemcached

别等时光非礼了梦想. 提交于 2019-12-24 09:14:18

问题


memcached_get (memcached_st *ptr,
               const char *key, size_t key_length,
               size_t *value_length,
               uint32_t *flags,
               memcached_return_t *error);

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.


回答1:


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.

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).



来源:https://stackoverflow.com/questions/3748917/question-with-memcached-get-in-libmemcached

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!