redis是ThinkPhp项目中最常用的缓存,今天绵阳动力网站建设为大家来介绍在thinkphp5框架中新增redis缓存的方法和代码。
首页是先到redis文件,路径如下:
thinkphp/library/think/cache/driver/Redis.php
接就是新增加缓存:在这里 我就举例几个 如何添加 添加的方法查看 redis教程。
完整代码如下:
/** * 返回列表中指定区间内的元素 * */ public function lrange($key,$start,$end){ return $this->handler->lrange($key,$start,$end); } /** * 在list左边新增元素 * */ public function lpush($key,$value){ return $this->handler->lPush($key,$value); } /** * 在list右边新增元素 * */ public function rpush($key,$value){ return $this->handler->rPush($key,$value); } /** * 返回并移除列表中的第一个元素 * */ public function lpop($key){ return $this->handler->lPop($key); } /** * 返回并移除列表的最后一个元素。 * */ public function rpop($key){ return $this->handler->rPop($key); }
如果还需要添加其他的方法 根据手册某个方法以及传值,去修改$this->handler-> 后面的方法函数。
好了,以上代码就是今天为大家介绍的thinkphp5框架中新增redis缓存的方法,如果你看了觉得用帮助,请记得收藏哦!
地址:绵阳市临园路东段78号B座13层
电话:0816-6339181
邮箱:kf@kf51.cn
微信公众号:
Copyright © 绵阳动力网站建设 www.kf51.cn All Rights Reserved 蜀ICP备08100083号