Memcache   发布时间:2022-05-11  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php memcache 一致性hash入门大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

<table class="text"><tr class="li1">
<td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

_hash($key);
        $node=current($this->nodes);// 默认在第一个服务器节点
 
        //通过判断所存key的hash值,与存储的服务器节点的key做对比,返回对应服务器的value值
        foreach ($this->nodes as $key => $value) {
            if($point<=$key){  =""  =""  =""  =""  =""  =""  =""  ="" $node="$value;"  =""  =""  =""  =""  =""  =""  =""  ="" break;=""  =""  =""  =""  =""  =""  ="" }=""  =""  =""  =""  ="" }=""  =""  =""  =""  ="" return="" $node;=""  =""  ="" }=""  =""  =""  ="" 添加服务器节点=""  =""  ="" public="" function="" addnode($node){=""  =""  =""  =""  ="" $node_key="sprintf('%u',crc32($node));"  =""  =""  =""  ="" $this-="">nodes[$node_key]=$node;// 按照键的节点排序
        $this->sortNode();
    }
 
    public function printNodes(){
        var_dump($this->nodes);// 打印所有服务器节点列表
    }
 
    //将所有服务器安装顺序大小排序,方便存储和查找
    public function sortNode(){
        ksort($this->nodes,SORT_REGULAR);
    }
}
 
$c=new Consitent();
$c->addNode('a');
$c->addNode('b');
$c->addNode('c');
$c->printNodes();
echo $c->_hash('name');
echo $c->lookup('name');

大佬总结

以上是大佬教程为你收集整理的php memcache 一致性hash入门全部内容,希望文章能够帮你解决php memcache 一致性hash入门所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。