<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">又到了一个能够沉思的夜晚。近期事情比較繁杂,大脑全然平静不下来。就想着研究点东西来平复一下。</span>
<?php /** *生成100个数据到memcache里。能够思考下,数据会怎么存储 */ $memClient = new Memcached(); $memClient->addServers(array(’10.21.1.11’,’11233’),array(’10.21.1.12’,’11233’)); for($i = 0;$i < 100;$i++){ $memClicent->set(“prefix_key_”.$i,$i,3600); }
<?php $memClient = new Memcached(); $memClient->addServers(array(’10.21.1.11’,’11233’),array(’10.21.1.12’,’11233’)); for($i = 0;$i < 100;$i++){ $memClicent->get(“prefix_key_”.$i); }
PHP_METHOD(Memcached, set) { php_memc_store_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, MEMC_OP_SET, 0); }
status = memcached_set(m_obj->memc, key, key_len, payload, payload_len, expiration, flags);
uint32_t server_key= memcached_generate_hash_with_redistribution(ptr, group_key, group_key_length); memcached_instance_st* instance= memcached_instance_fetch(ptr, server_key);
return hashkit_digest(&ptr->hashkit, key, key_length);返回一个长整型,返回的这个值就是路由到哪个server的关键
return self->base_hash.function(key, key_length, self->base_hash.context);
status = memcached_set(m_obj->memc, key, key_len, payload, payload_len, expiration, flags);这里有个m_obj->memc。这是memcached_set传递的第一个參数,于是self->base_hash能够想像成
m_obj->memc->hashkit->base_hash.function(key, key_length, self->base_hash.context);
typedef struct { zend_object zo; struct memc_obj { memcached_st *memc; zend_bool compression; enum memcached_serializer serializer; enum memcached_compression_type compression_type; #if HAVE_MEMCACHED_SASL zend_bool has_sasl_data; #endif long store_retry_count; } *obj; zend_bool is_persistent; zend_bool is_pristine; int rescode; int memc_errno; } php_memc_t;
struct hashkit_st { struct hashkit_function_st { hashkit_hash_fn function; void *context; } base_hash, distribution_hash; struct { bool is_base_same_distributed:1; } flags; struct { bool is_allocated:1; } options; void *_key; };
if (hashkit_create(&self->hashkit) == NULL) { return false; }
static inline void _hashkit_init(hashkit_st *self) { self->base_hash.function= hashkit_one_at_a_time; self->base_hash.context= NULL; self->distribution_hash.function= hashkit_one_at_a_time; self->distribution_hash.context= NULL; self->flags.is_base_same_distributed= true; self->_key= NULL; }
#include <libhashkit/common.h> uint32_t hashkit_one_at_a_time(const char *key, size_t key_length, void *context) { const char *ptr= key; uint32_t value= 0; (void)context; while (key_length--) { uint32_t val= (uint32_t) *ptr++; value += val; value += (value << 10); value ^= (value >> 6); } value += (value << 3); value ^= (value >> 11); value += (value << 15); return value; }
原文:http://www.cnblogs.com/wzzkaifa/p/6898548.html