Memcached Cache类

浏览:6965 最后更新:2014-10-29 17:45 分类:驱动 关键字: memcached 驱动 cache驱动
把php文件放到TP的Cache驱动目录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 '<br>user1='.S('user1');
        echo '<br>user2='.S('user2');
        echo '<br>user3='.S('user3');
        echo '<br>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));
评论( 相关
后面还有条评论,点击查看>>