php 封装memcache类

<?php/** memcache类 */class Memcacheds{ //声明静态成员变量 private static $m = null; private static $cache = null; private function __construct() { self::$m = new Memcache(); self::$m->connect(‘www.cat.com’,’11211′); //写入缓存地址,端口 } //为当前类创建对象 private static function Men(){ self::$cache = new Memcacheds(); return self::$m; } /* * 添加缓存数据 * @param string $key 获取数据唯一key * @param String||Array $value 缓存数据 * @param $time memcache生存周期(秒) */ public static function setMen($key,$value,$time){ self::Men()->set($key,$value,0,$time); } /* * 获取缓存数据 * @param string $key * @return */ public static function getMen($key){ return self::Men()->get($key); } /* * 删除对应缓存数据 * @param string $key * @return */ public static function delMen($key){ self::Men()->delete($key); } /* * 删除所有缓存数据 */ public static function delAllMen(){ self::Men()->flush(); } /* * 删除所有缓存数据 */ public static function menStatus(){ return self::Men()->getStats(); }

}

<———————————————————–>

调用类

<?php

include_once ‘memcache.php’; 引入类文件

$key = ‘myKey’;$value = ‘insert into 12334234’;$time = 60;Memcacheds::setMen($key,$value,$time); //写入缓存$get = Memcacheds::getMen($key); //读取echo ‘<pre>’;print_r($get);

?>

结果输出:

insert into 12334234

版权声明:本文为博主原创文章,未经博主允许不得转载。

,梦想让我与众不同,奋斗让我改变命运!

php 封装memcache类

相关文章:

你感兴趣的文章:

标签云: