memcache在tp3.2中的使用

 时间:2026-02-13 11:47:12

1、先看下服务是否开启来了,如何安装和开启memcached请看我前面一篇经验。

memcache在tp3.2中的使用

2、在web目录下新建phpinfo.php内容

<?php phpinfo();

然后在浏览器中输入localhost/phpinfo.php访问

查找下看是否已经安装好memcache扩展了。

memcache在tp3.2中的使用

3、在tp3.2的配置文件中config.php 添加

    'DATA_CACHE_TIME'        => 1800,        // 数据缓存有效期s

    'DATA_CACHE_TYPE' => 'Memcache',   //数据缓存类型

    'MEMCACHE_HOST'   => 'tcp://127.0.0.1:11211',

memcache在tp3.2中的使用

4、memcache的实例化,设置内容和获取内容方式一

在IndexController的index方法中加入以下内容做个测试

//连接

$mem = new \Think\Cache\Driver\Memcache;

$mem->set('key1', 'This is first value', 0, 60);

$val = $mem->get('key1'); 

echo "Get key1 value: " . $val ."<br />";

$class = new \Think\Cache\Driver\Memcache();  

$class->set('key','1234');  

$data = $class->get('key');  

echo $data;  

memcache在tp3.2中的使用

5、memcache设置内容和获取内容方式二,调用S方法。

在IndexController的index方法中加入以下内容做个测试

S('test','hello memcache');

$mem_test = S('test');

echo $mem_test; //输出hello memcache表示成功

memcache在tp3.2中的使用

6、效果展示。

memcache在tp3.2中的使用

  • 使用Telnet来操作memcache服务
  • MemCache的实例应用
  • memcache的基本命令
  • php操作memcache
  • Windows下memcache简单使用
  • 热门搜索
    怎么办签证 烧心怎么回事 鳄鱼怎么玩 考试总结怎么写 成都中医药大学怎么样 笔记本电脑怎么放光盘 子网掩码怎么设置 cad角度怎么画 怎么注册淘宝账号 亚索怎么玩