zoukankan      html  css  js  c++  java
  • Memcache的增删改查

    Memcache是把数据存放到内存的一种缓存技术,为了提高访问的速度,memcache存储的数据一般是频繁、不太重要的数据,php使用memcache,需要两步:

    (1).php_memcache.dll 文件拷贝到php的ext下
    (2)php.init 添加 extension=php_memcache.dll,重启apache
    还有一点需要注意,php有两个扩展库,php_memcache.dll和php_memcached.php,下面的代码,是以php_memcache.dll的扩展库做的测试
    // phpinfo();exit;
    $memcache = new Memcache; //创建一个memcache对象  
    $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器  
    //1.保存数值
    $value=123;
    //2.保存字符串
    $value="abc";
    //3.保存数组
    $value=array('name','vic');
    //4.保存对象
    class dog{
      private $name;
      private $age;
      function __construct($name,$age){
          $this->name=$name;
          $this->age=$age;
      }
    }
    $value=new dog('小狗',12);
    //5.null
    $value=null;
    //6.不可以保存资源
    
    //在添加数据,如果超时设为0,表示永不过期,最大存30天,如果想存放30以上,time()*31*3600*24
    // $memcache->add('key', $value,MEMCACHE_COMPRESSED,100);
    $memcache->set('key', $value,MEMCACHE_COMPRESSED,100); //设置一个变量到内存中,名称是key 值是test  
    
    
    //修改
    $memcache->replace('key','4546',MEMCACHE_COMPRESSED,100);
    
    //获取
    $get=$memcache->get('key');
    
    
    //删除
    $memcache->delete('key');
    var_dump($get);
  • 相关阅读:
    day6 面向对象(2)
    day5 面向对象
    day4 函数重载
    sqlserver 存储过程 增加
    sqlserver 存储过程 修改
    sqlserver 存储过程 删除
    sqlserver 存储过程 查询
    上篇: php 微信公众号 基于Thinkphp3.2框架开发
    bzoj 2726: [SDOI2012]任务安排
    bzoj 4199 [NOI2015]寿司晚宴
  • 原文地址:https://www.cnblogs.com/myvic/p/5905099.html
Copyright © 2011-2022 走看看