首页 > 作文

PHP教程:php操作memcached方法实例

更新时间:2023-04-08 13:46:08 阅读: 评论:0

1首先建立clsss类文件memcached.class.php

&l星空下的约定t;?phpclass memcacheds{    //声明静态成员变量    private static $m = null;    private static $cache = null;        public function __construct() {        lf::$m = new memcached();               lf::忽复乘舟梦日边的上一句$m->addrver('127.0.0.1','11211'); //写入缓存地址,port    }    //为当前类创建对象    private static function men(){        lf::$cache = new memcacheds();        return lf::$m;    }        /*     * 加入缓存数据     * @param string $key 获取数据唯一key     * @p王杰的经典歌曲aram string||array $value 缓存数据     * @param $time memcache生存周期(秒)     */    public static function tmen($key,$value,$time){        lf::men()->t($key,$value,$time);    }    /*     * 获取缓存数据     * @param string $key     * @return     */    public static functio灯的英语单词n getmen($key){        return lf::men()->get($key);    }    /*     * 删除相应缓存数据     * @param string $key     * @return     */    public static function delmen($key){        lf::men()-&Dota鱼人夜行者gt;delete($key);    }    /*     * 删除全部缓存数据     */    public static function delallmen(){        lf::men()->flush();    }        /*     * 删除全部缓存数据     */    public static function menstatus(){        return lf::men()->getstats();    }}?>

2使用方法实例

//引入类文件require dirname(__file__).'/memcached.class.php';function get_memcached($str,$key,$time){    $key = md5($key);    memcacheds::tmen($key,$str,$time); //写入缓存    $get = memcacheds::getmen($key); //读取缓存    return $get;}echo function get_memcached('data','key',3600);

希望本文所述对大家的php程序设计有所帮助。

原文来源:

本文发布于:2023-04-08 13:46:06,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/8163e1e9b88e05c9a5059118dea8ea70.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP教程:php操作memcached方法实例.doc

本文 PDF 下载地址:PHP教程:php操作memcached方法实例.pdf

下一篇:返回列表
标签:缓存   数据   文件   一句
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图