时间:2021-07-01 10:21:17 帮助过:3人阅读
redis = new Redis(); $this->redis->connect(self::REDISHOSTNAME, self::REDISPORT, self::REDISTIMEOUT); $this->redis->auth(self::REDISPASSWORD); $this->redis->select(self::REDISDBNAME); } /** * 私有化克隆函数,防止类外克隆对象 */ private function __clone () {} /** * 类的唯一公开静态方法,获取类单例的唯一入口 * * @return object */ public static function getRedisInstance () { if (! (self::$instance instanceof self)) { self::$instance = new self(); } return self::$instance; } /** * 获取redis的连接实例 * * @return Redis */ public function getRedisConn () { return $this->redis; } /** * 需要在单例切换的时候做清理工作 */ public function __destruct () { self::$instance->redis->close(); self::$instance = NULL; } } ?>
http://www.bkjia.com/PHPjc/929776.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/929776.htmlTechArticlephp 连接redis 数据库单利类 redis = new Redis(); $this->redis->connect(self::REDISHOSTNAME, self::REDISPORT, self::REDISTIMEOUT); $this->redis->auth(self::REDISPASSWORD); $t...