I am using libmemcached c client for set and get the memcache value.
memcached_server_st *servers = NULL;
memcached_st *memc;
memcached_return rc;
char *key= "keystring";
char *value= "keyvalue";
// memcached_server_st *memcached_servers_parse (char *server_strings);
memc= memcached_create(NULL);
servers= memcached_server_list_append(servers, "localhost", 5555, &rc);
servers= memcached_server_list_append(servers, "localhost", 5566, &rc);
rc= memcached_server_push(memc, servers);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Added server successfully\n");
else
fprintf(stderr,"Couldn't add server: %s\n",memcached_strerror(memc, rc));
rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Key stored successfully\n");
else
fprintf(stderr,"Couldn't store key: %s\n",memcached_strerror(memc, rc));
return 0;
I want to use the consistent hashing algorithm for set and get the key. http://docs.libmemcached.org/memcached_behavior.html#memcached_behavior_setlink
But i don't know how to implement this.code snippets or reference links are very much appreciated.
Thanks in advance.
Go to the link http://docs.libmemcached.org/memcached_behavior.html#memcached_behavior_setlink You can see two method to make it.
first one
MEMCACHED_BEHAVIOR_DISTRIBUTION
Using this you can enable different means of distributing values to servers.
The default method is MEMCACHED_DISTRIBUTION_MODULA. You can enable consistent hashing by setting MEMCACHED_DISTRIBUTION_CONSISTENT. Consistent hashing delivers better distribution and allows servers to be added to the cluster with minimal cache losses. Currently MEMCACHED_DISTRIBUTION_CONSISTENT is an alias for the value MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA.
second one
MEMCACHED_BEHAVIOR_KETAMA
Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and the hash to MEMCACHED_HASH_MD5.
example
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1);