当前位置: 首页 > news >正文

为XiunoBBS4.0开启redis缓存且支持密码验证

修改模块文件1

xiunoPHP/cache_redis.class.php:

<?phpclass cache_redis {public $conf = array();public $link = NULL;public $cachepre = '';public $errno = 0;public $errstr = '';public function __construct($conf = array()) {if(!extension_loaded('Redis')) {return $this->error(-1, ' Redis 扩展没有加载');}$this->conf = $conf;$this->cachepre = isset($conf['cachepre']) ? $conf['cachepre'] : 'pre_';}public function connect() {if($this->link) return $this->link;$redis = new Redis;$r = $redis->connect($this->conf['host'], $this->conf['port']);if(!$r) {return $this->error(-1, '连接 Redis 服务器失败。');}//$redis->select('xn');$this->link = $redis;return $this->link;}public function set($k, $v, $life = 0) {if(!$this->link && !$this->connect()) return FALSE;$v = xn_json_encode($v);$r = $this->link->set($k, $v);$life AND $r AND $this->link->expire($k, $life);return $r;}public function get($k) {if(!$this->link && !$this->connect()) return FALSE;$r = $this->link->get($k);return $r === FALSE ? NULL : xn_json_decode($r);}public function delete($k) {if(!$this->link && !$this->connect()) return FALSE;return $this->link->del($k) ? TRUE : FALSE;}public function truncate() {if(!$this->link && !$this->connect()) return FALSE;return $this->link->flushdb(); // flushall}public function error($errno = 0, $errstr = '') {$this->errno = $errno;$this->errstr = $errstr;DEBUG AND trigger_error('Cache Error:'.$this->errstr);}public function __destruct() {}
}?>

找到该行

$r = $redis->connect($this->conf['host'], $this->conf['port']);

另起一行新增以下代码

if($this->conf['password']!==null){if($redis->auth($this->conf['password']) == false){return $this->error(-1, 'Redis 服务器密码错误。');}}


修改模块文件2

xiunophp/xiunophp.min.php:

找到该行

$r = $redis->connect($this->conf['host'], $this->conf['port']);

在后面添加下面内容:

if($this->conf['password']!==null){if($redis->auth($this->conf['password']) == false){return $this->error(-1, 'Redis 服务器密码错误。');}}

保存即可


修改Conf.php

conf/conf.php:

'redis' => array ('host' => 'localhost','port' => '6379','cachepre' => 'bbs_',),

新增一个password字段

'redis' => array ('host' => 'localhost','port' => '6379','password' => 'password','cachepre' => 'bbs_',),

开启Redis缓存


本来是mysql的, 改为redis

php一定要安装redis扩展

最后清理一下缓存即可完成~

http://www.lryc.cn/news/251978.html

相关文章:

  • 手把手教你写一个Shell脚本部署你的服务
  • 银行数字化产品方案
  • C# datagridview控件 绑定数据库中表中数据的方式-3
  • Amazon CodeWhisperer 正式发布可免费供个人使用
  • el-table根据返回数据回显选择复选框
  • 代码随想录算法训练营第四十二天 _ 动态规划_01背包问题。
  • 会话 cookie 及隐私的那些事
  • 前端知识笔记(二十九)———MySQL通配符和正则表达式
  • C#网络编程(System.Net.Sockets命名空间)
  • linux 系统重装 ssh 连接失败
  • stream流操作List对象,指定属性,取差集、交集
  • 计算机相关行业在大数据库时代下的潮流和趁势
  • Mac苹果视频剪辑:Final Cut Pro Mac
  • 高德Map
  • SSM新闻发布管理系统
  • 客户销售目标拆解:数据驱动的方法和策略
  • “丝路电商”与泛欧在线公共采购平台Peppol
  • 今日思考 -- 创新领导力(CIO)读后感
  • Python实现Excel自动化
  • WT2605-24SS高品质录音语音芯片:实现五种变音效果,为音频应用增添无限创意
  • 最美早安心语问候朋友们,祝你心情美好,万事如意
  • 2312skia,16画布
  • mysql文本类型的最大长度限制
  • ASP.NET《数据库原理及应用技术》课程指导平台的开发
  • OSHI-操作系统和硬件信息库
  • 基于Java SSM框架+Vue实现企业公寓后勤管理系统项目【项目源码+论文说明】计算机毕业设计
  • stm32mp157和imx6ull在设备树节点上设置ap3216c的主要区别
  • 网工学习6-配置和管理 VLAN
  • MySQL库与表的备份
  • Python核心编程之基础内功