<?php

/**
* memcache 操作实现
* @author timeless
*/
class Memcache_manage { //CI原始的信息
private $_ci;
private $_memcache_prefix;
private $host;
private $port;
private $expire;
private $weight; /**
* 读取配置文件信息然后更新
* @access public
*/
public function memcache($flag = 'default') {
//要你自定义的类库中访问CodeIgniter的原始资源,你必须使用 get_instance() 函数.这个函数返回一个CodeIgniter super object.
$this->_ci = &get_instance();
//记载memcache 缓存配置     //memcached 中的数据     /* memcahed.php 文件中的配置信息 CI框架中
$config = array(
//现在是单独的memcache 服务器 以后可以添加多个 只需要 mem 对象添加 addserver
'default' => array(
'hostname' => '127.0.0.1',
'port' => '11211',
'weight' => '1',
//100分钟
'expire' => '6000',
'memcache_prefix'=>'',
),
);
     */
$this->_ci->config->load('memcached', FALSE, TRUE);
//获取配置文件
$default_conf = $this->_ci->config->item('default');
$this->host = $default_conf['hostname'];
$this->port = $default_conf['port'];
$this->expire = $default_conf['expire'];
$this->weight = $default_conf['weight'];
$this->_memcache_prefix = $default_conf['memcache_prefix'];
$this->connected_server = array();
$this->_connect();
} /**
* 连接memcache 数据库
* @access private
*/
private function _connect() {
if (function_exists('memcache_connect')) {
$this->cache = new Memcache;
$this->_connect_memcached();
}
} /**
* 添加memcache 服务器
* @access private
*/
private function _connect_memcached() {
$error_display = ini_get('display_errors');
$error_reporting = ini_get('error_reporting');
if ($this->cache->addServer($this->host, $this->port, TRUE, $this->weight)) {
$this->connected_server[] = $this->host;
}
ini_set('error_reporting', $error_reporting);
} public function get($key) {
if (empty($this->connected_server)) {
return false;
}
return $this->cache->get($this->key_name($key));
} public function set($key, $data) {
if (empty($this->connected_server)) {
return false;
}
return $this->cache->set($this->key_name($key), $data, 0, $this->expire);
} public function set_expire($key, $data, $expire) {
if (empty($this->connected_server)) {
return false;
}
return $this->cache->set($this->key_name($key), $data, 0, $expire);
} public function replace($key, $data) {
if (empty($this->connected_server)) {
return false;
}
return $this->cache->replace($this->key_name($key), $data, 0, $this->expire);
} public function delete($key, $when = 0) {
if (empty($this->connected_server)) {
return false;
}
return $this->cache->delete($this->key_name($key), $when);
} public function flush() {
return $this->cache->flush();
} /**
* @Name: 生成md5加密后的唯一键值
* @param:$key key
* @return : md5 string
* */
private function key_name($key) {
return md5(strtolower($this->_memcache_prefix . $key));
} }

memcache 操作类的更多相关文章

  1. PHP 对 memcache操作类

    <span style="font-size:18px;">class myMemcache { private $memcache; /** * 一般建议这2个值做成 ...

  2. Memcache操作类

    using Memcached.ClientLibrary; using System; using System.Collections.Generic; using System.Linq; us ...

  3. 设计模式之PHP项目应用——单例模式设计Memcache和Redis操作类

    1 单例模式简单介绍 单例模式是一种经常使用的软件设计模式. 在它的核心结构中仅仅包括一个被称为单例类的特殊类. 通过单例模式能够保证系统中一个类仅仅有一个实例并且该实例易于外界訪问.从而方便对实例个 ...

  4. ecshop的Mysql操作类

    摘要,这是直接摘抄的ecshop的mysql操作类:不过他这里的缓存是用的文件缓存,我们如果想直接使用,可以替换成memcache的或者redis的! <?php /** * ECSHOP MY ...

  5. 3.NetDh框架之缓存操作类和二次开发模式简单设计(附源码和示例代码)

    前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...

  6. 【知识必备】ezSQL,最好用的数据库操作类,让php操作sql更简单~

    最近用php做了点小东东,用上了ezSQL,感觉真的很ez,所以拿来跟大家分享一下~ ezSQL是一个非常好用的PHP数据库操作类.著名的开源博客WordPress的数据库操作就使用了ezSQL的My ...

  7. JQuery操作类数组的工具方法

    JQuery学习之操作类数组的工具方法 在很多时候,JQuery的$()函数都返回一个类似数据的JQuery对象,例如$('div')将返回div里面的所有div元素包装的JQuery对象.在这中情况 ...

  8. Util应用程序框架公共操作类(十二):Lambda表达式公共操作类(三)

    今天在开发一个简单查询时,发现我的Lambda操作类的GetValue方法无法正确获取枚举类型值,以至查询结果错误. 我增加了几个单元测试来捕获错误,代码如下. /// <summary> ...

  9. Util应用程序框架公共操作类(九):Lambda表达式扩展

    上一篇对Lambda表达式公共操作类进行了一些增强,本篇使用扩展方法对Lambda表达式进行扩展. 修改Util项目的Extensions.Expression.cs文件,代码如下. using Sy ...

随机推荐

  1. NTP服务器

    server 1.cn.pool.ntp.org server 1.asia.pool.ntp.org server 0.asia.pool.ntp.org pool.ntp.org

  2. GDI+ —— Tcanvas 类属性及方法.......

    delphi TCanvas类 类关系   TObject-> TPersistent   对那些作图对象,可使用TCanvas对象作为画布.标准的window控件,例如编辑控件和列表框控件,当 ...

  3. zendstudio xdebug 配置

    1. 下载XDebug: http://www.xdebug.org/download.php   通过phpinfo()查看你的php版本,现在相对应的dll文件

  4. hdoj 1599 find the mincost route【floyd+最小环】

    find the mincost route Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  5. 移动设备、手机浏览器Javascript滑动事件代码

    以下经过本人测试成功. 测试平台:三星S5830I 操作系统:Android 2.3.6 浏览器:UC浏览器 HTML标准:HTML5 测试了三个事件:touchstart.touchmove 和 t ...

  6. 改变Android按钮背景颜色的高效方法

    本文将介绍一种有效改变Android按钮颜色的方法. 按钮可以在状态改变时改变其颜色(例如按下,禁用,高亮显示).但是,这需要一一说明每个状态.这篇文章将提供你一个根据状态变化轻松改变按钮颜色的方法. ...

  7. 一个备份MySQL数据库的简单Shell脚本(转)

    Shell脚本是我们写不同类型命令的一种脚本,这些命令在这一个文件中就可以执行.我们也可以逐一敲入命令手动执行.如果我们要使用shell脚本就必须在一开始把这些命令写到一个文本文件中,以后就可以随意反 ...

  8. 关于MySQL的各种总结

    https://blog.atime.me/note/mysql-summary.html 总结使用MySQL过程中遇到的各种问题和一些有用的资源,配置等等.将之前的若干篇零散的文章汇总到一起,备忘. ...

  9. 『零行代码』解决键盘遮挡问题(iOS)

    关注仓库,及时获得更新:iOS-Source-Code-Analyze https://github.com/draveness/iOS-Source-Code-Analyze Follow: Dra ...

  10. FastDFS配置说明(中英文)

    FastDFS配置说明 1)tracker.conf # is this config file disabled # false for enabled # true for disabled di ...