多组多服务器Memcached服务器的调用
我用的是多组多服务器模式,有没有人针对我下面的需求给个配置文件$memcached['maingroup']=array(
array('host'=>‘192.168.0.1’,weight=2),
array('host'=>’192.168.0.2‘,weight=3)
);
$memcached['other']=array(
array('host'=>’192.168.0.3‘,weight=2),
array('host'=>‘192.168.0.4’,weight=3)
);
就是这个意思,谁能告诉我在CI 2.0下面 我要怎么改动文件?怎么调用? 还是自己搞定了,我把步骤和代码贴出来,以供未来人直接用
1、在application/models里面建立文件memcache_model.php(注意文件名和大小写)
内容如下<?php
class Memcache_model extends CI_Model {
public static $memcached = array(
‘maingroup' => array(
array('host' => '192.168.0.1', 'port' => '11211', 'weight' => 10),
array('host' => '192.168.0.2', 'port' => '11211', 'weight' => 50),
),
'other' => array(
array('host' => '192.168.0.3', 'port' => '11212', 'weight' => 10),
array('host' => '192.168.0.4', 'port' => '11211', 'weight' => 50),
)
);
final public function instance($group='other') {
$memcache = new Memcache;
foreach (self::$memcached[$group] as $v) {
$memcache->addserver($v['host'], $v['port'], 1, $v['weight']); //1 表示长连接
}
return $memcache;
}
}
2、在application/controllers下面建立cachetest.php文件
内容如下:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Cachetest extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('Memcache_model');
}
function index() {
$key = 'good';
$value = 'goodvalue';
$memcacheObj = $this->Memcache_model->instance('other');
$memcacheObj->set($key, $value);
print_r($memcacheObj->get($key));
}
}
3、运行http://XXX.XXX.com/cachetest 看看效果吧! 牛人,顶!!! :L 2.0自带memcached支持的,在cache driver里面 1、我是刚入门的,想知道我这种应用怎么和memcached搭上线,可是看不到一个示例程序。
2、pecl-memcached和pecl-memcache,我觉得大部分机器还是安装了pecl-memcache,这个和Codeigniter自带的不一样,总要有人能够写出一个适合大众的东西来。
3、请斑竹帮忙讲讲,我的需求用memcached怎么实现,给我个例程。
在此谢过! ci memcached driver目前还没有官方的详细配置方法,
楼主可以看下memcached driver写配置文件 谢谢版主提示,
1、我就是阅读能力不强,所以才写这个东东的
2、memcached的driver,很多服务器没有安装呢……
3、我对CI的memcached也非常期待,尤其是多key值操作方面。
各位高手,加油啊! memcached要自己去pecl下载源码编译。。。网上没有现成的.so和.dll,很悲剧 是啊,我们用的是pecl-memcache而不是pecl-memcached,要升级一次,就要动几十台机器的php,好大的工作量,所以只好用pecl-memcache
页:
[1]