Home > php教程 > PHP源码 > body text

Memcached分布式部署方案设计(含PHP代码)

PHP中文网
Release: 2016-06-01 14:32:35
Original
938 people have browsed it

php代码

<?php
function test($key=&#39;name&#39;){
    $md5 = substr(md5($key), 0, 8);
    $seed = 31;
    $hash = 0;
    for($i=0; $i&#39;192.168.1.2&#39;, &#39;port&#39;=>6379),
        array(&#39;host&#39;=>&#39;192.168.1.3&#39;, &#39;port&#39;=>6379),
        array(&#39;host&#39;=>&#39;192.168.1.4&#39;, &#39;port&#39;=>6379),
        array(&#39;host&#39;=>&#39;192.168.1.5&#39;, &#39;port&#39;=>6379),
);
$key = &#39;username&#39;;
$value = &#39;lane&#39;;
//根据KEY获取hash
$hash = $this->test($key);
$count = count($mamcacheList);
$mamcache = $mamcacheList[$hash % $count];
$mc = new Mamcached($mamcache);
$mc->set($key, $value);
?>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template