Memcached Cache类
程序员文章站
2024-01-15 20:42:58
...
最近在学习TP,发现TP下只有memcache的缓存类没有memcached的,就加了一个
代码文件在这里
http://www.thinkphp.cn/extend/485.html
放到TP的Extend/Driver/Cache下,在config.php里配置
代码文件在这里
http://www.thinkphp.cn/extend/485.html
放到TP的Extend/Driver/Cache下,在config.php里配置
'DATA_CACHE_TYPE' => 'Memcached',
// 'PERSISTENTID'=>'tp',//可选
'MEMCACHED_HOST' => array('127.0.0.1','127.0.0.1'),
'MEMCACHED_PORT' => array('11211','11212'),
// 'MEMECACHED_WEIGHT' => array(33,67),//可选
使用:和其它缓存一样直接使用S方法就可以S('userName','wahaha',20);
echo 'userName=='.S('userName');
S('user1','wahaha-1',60);
S('user2','wahaha-3',60);
S('user3','wahaha-4',60);
S('user5','wahaha-5',60);
echo '
user1='.S('user1');
echo '
user2='.S('user2');
echo '
user3='.S('user3');
echo '
user5='.S('user5');
//
$memcached = new CacheMemcached();
$data = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
);
$memcached->setMulti($data,60);
$key = array('key1','key2','key3');
p($memcached->getMulti($key));
$memcached->rm('key2');
p($memcached->getMulti($key));
$memcached->set('key88','value88',60);
p($memcached->get('key88'));
$memcached->clear();
p($memcached->getMulti($key));
AD:真正免费,域名+虚机+企业邮箱=0元