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

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

修改模块文件1

xiunoPHP/cache_redis.class.php:

<?php

class 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.kler.cn/a/158140.html

相关文章:

  • 生产实践:基于K8S的私有化部署解决方案
  • “谢湖大樱桃”区域公用品牌形象正式发布
  • leetcode算法之栈
  • YOLOv3 快速上手:Windows 10上的训练环境搭建
  • RHCSA学习笔记(RHEL8) - Part1.RH124
  • 12、SQL注入——SQL报错注入
  • IDEA中,Archetype的作用
  • 【开源】基于JAVA的厦门旅游电子商务预订系统
  • 23史上最全版---SQL注入详解
  • Vue3中props传参(多种数据类型传参方式)
  • 使用python+poco+夜神模拟器进行自动化测试实例
  • 全球葡萄酒行业对社会的积极和消极影响
  • 【Git】Git撤销操作
  • oracle 19c rac 安装手册
  • Golang线程池与协程池
  • 全国网络与信息安全管理员职工职业技能竞赛线下培训—简单的流量分析
  • 欢迎回到 C++ - 现代 C++(心得-壹)
  • Atcoder Beginner Contest 331 A~F
  • Python 文本终端 GUI 框架详解
  • 科技论文中的Assumption、Remark、Property、Lemma、Theorem、Proof含义