#include <ctime>
#include <sys/types.h>
+static bool __is_ketama(memcached_st *ptr)
+{
+ switch (ptr->distribution)
+ {
+ case MEMCACHED_DISTRIBUTION_CONSISTENT:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED:
+ return true;
+
+ case MEMCACHED_DISTRIBUTION_MODULA:
+ case MEMCACHED_DISTRIBUTION_RANDOM:
+ case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX:
+ break;
+ }
+
+ return false;
+}
+
/*
This function is used to modify the behavior of running client.
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
{
+ if (bool(data) == false)
+ {
+ return memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_KETAMA, true);
+ }
+
(void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_MD5);
(void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_MD5);
- ptr->ketama.weighted= bool(data);
/**
@note We try to keep the same distribution going. This should be deprecated and rewritten.
*/
- return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA);
+ return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED);
}
case MEMCACHED_BEHAVIOR_HASH:
return ptr->flags.verify_key;
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
- return ptr->ketama.weighted;
+ if (__is_ketama(ptr))
+ {
+ return ptr->ketama.weighted;
+ }
+ return false;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
return ptr->distribution;
case MEMCACHED_BEHAVIOR_KETAMA:
- return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0;
+ return __is_ketama(ptr);
case MEMCACHED_BEHAVIOR_HASH:
return hashkit_get_function(&ptr->hashkit);
return (uint64_t) ptr->send_size;
}
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
if (instance) // If we have an instance we test, otherwise we just set and pray
{
if (ptr->recv_size != -1) // If value is -1 then we are using the default
return (uint64_t) ptr->recv_size;
- memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, 0);
+ org::libmemcached::Instance* instance= memcached_instance_fetch(ptr, 0);
/**
@note REFACTOR
memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcached_server_distribution_t type)
{
- if (type < MEMCACHED_DISTRIBUTION_CONSISTENT_MAX)
+ switch (type)
{
- if (MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED)
- {
- ptr->ketama.weighted= true;
- }
- else
- {
- ptr->ketama.weighted= false;
- }
+ case MEMCACHED_DISTRIBUTION_MODULA:
+ break;
+
+ case MEMCACHED_DISTRIBUTION_CONSISTENT:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA:
+ ptr->ketama.weighted= false;
+ break;
+
+ case MEMCACHED_DISTRIBUTION_RANDOM:
+ break;
+
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
+ break;
- ptr->distribution= type;
- return run_distribution(ptr);
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED:
+ ptr->ketama.weighted= true;
+ break;
+
+ case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET:
+ break;
+
+ default:
+ case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX:
+ return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
+ memcached_literal_param("Invalid memcached_server_distribution_t"));
}
+ ptr->distribution= type;
- return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
- memcached_literal_param("Invalid memcached_server_distribution_t"));
+ return run_distribution(ptr);
}
memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *ptr, memcached_hash_t type)
{
if (hashkit_success(hashkit_set_distribution_function(&ptr->hashkit, (hashkit_hash_algorithm_t)type)))
+ {
return MEMCACHED_SUCCESS;
+ }
return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT,
memcached_literal_param("Invalid memcached_hash_t()"));