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

news/2024/5/18 11:51:54 标签: redis, xiuno, bbs, xiunobbs, 缓存

修改模块文件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.niftyadmin.cn/n/5232293.html

相关文章

uniapp小程序分包页面引入wxcomponents(vue.config.js、copy-webpack-plugin)

实例&#xff1a;小程序添加一个源生小程序插件&#xff0c;按照uniapp官方的说明&#xff0c;要放在wxcomponents。后来发现小程序超2m上传不了。 正常的编译情况 会被编译到主包下 思路&#xff1a;把wxcomponents给编译到分包sub_package下 用uniapp的vue.config.js自定义…

Deckerfile

1.简介 dockerfile 是 docker 镜像构建文件。包含用于构建 docker 镜像的指令和配置。通过Dockerfile可以自动化地构建Docker镜像&#xff0c;实现快速、一致和可重复的部署。是由一条条构建镜像所需的指令和参数构成的脚本。指令按照从上到下&#xff0c;顺序执行&#xff0c…

WordPress采集器自动采集发布的工具

WordPress作为最受欢迎的内容管理系统之一&#xff0c;其强大的功能和灵活性使其成为许多网站、博客和电子商务平台的首选。WordPress采集器自动采集发布内置采集规则是一项备受关注的功能&#xff0c;让用户可以轻松收集并发布内容。WordPress采集器自动采集发布内置采集规则的…

Selenium+Python自动化测试之验证码处理

两种方式&#xff1a; 验证码识别技术 (很难达到100%) 添加Cookie &#xff08;*****五星推荐&#xff09; 方式一&#xff1a;验证码识别技术 逻辑方式&#xff1a; 1&#xff1a;打开验证码所在页面&#xff0c;截图。获取验证码元素坐标&#xff0c;剪切出验证码图片&…

文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑碳排放分摊的综合能源服务商交易策略》

这篇文章的标题表明它将讨论一个关于综合能源服务商交易策略的主题&#xff0c;而在这个策略中&#xff0c;特别考虑了碳排放分摊的因素。以下是对标题中各关键词的解读&#xff1a; 综合能源服务商&#xff1a; 这指的是在能源领域提供多种服务的企业或组织&#xff0c;可能涵…

代数学笔记8: Sylow定理

Sylow定理 ∣ G ∣ p r ⋅ m |G|p^r\cdot m ∣G∣pr⋅m, ( m , p ) 1 (m,p)1 (m,p)1, 则 G G G中必有 p r p^r pr阶子群. 证明: 应用 例子: 15阶群必定是循环群. 因为 15 3 5 153\times 5 1535, 所以15阶群有 3 3 3阶群或 5 5 5阶群, 设3阶群有 n 3 n_3 n3​个, 5阶群有…

JS 实现一键复制文本内容

1、演示&#xff1a; 2、代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>一键复制</title&g…

泛型和Object的区别

什么时候使用 泛型&#xff1a;只要确定了用哪类对象&#xff0c;并且用到这个对象里的方法。选择泛型&#xff0c;泛型更加精确&#xff0c;只要用到Object的地方基本都能用泛型代替。Object类&#xff1a;Object是所有类的父类&#xff0c;更加笼统&#xff0c;且只能使用固…