Home >php教程 >PHP源码 >Memcached分布式部署方案设计(含PHP代码)

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

PHP中文网
PHP中文网Original
2016-06-01 14:32:35985browse

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);
?>

Statement:
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
Previous article:封装 Twitter 访问的 PHP 类Next article:PHP短信*