脚本宝典收集整理的这篇文章主要介绍了PHP实现的Redis多库选择功能单例类,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了PHP实现的redis多库选择功能单例类。分享给大家供大家参考,具体如下:
QQ群里有同学问redis如何进行多库选择,用PHP实现了一下,还望各位多多指点
PHP;"> hash = $dbnumber; $this->redis = new Redis(); $this->redis->connect(self::REDISHOSTNAME,self::REDISPORT,self::REDISTIMEOUT); $this->redis->auth(self::REDISPASSWORD); $this->redis->select($dbnumber); } private function __clone () {} /** * 获取类单例 * * @param int $dbnumber * @return object */ public static function getRedisinstance ($dbnumber) { $hash = (int) $dbnumber; if (! isset(self::$instance[$hash])) { self::$instance[$hash] = new MultiRedisConnect($dbnumber); } return self::$instance[$hash]; } /** * 获取redis的连接实例 * * @return object */ public function getRedisConnect () { return $this->redis; } /** * 关闭单例时做清理工作 */ public function __destruct () { $key = $this->hash; self::$instances[$key]->redis->close(); self::$instances[$key] = null; } } ?>
以上是脚本宝典为你收集整理的PHP实现的Redis多库选择功能单例类全部内容,希望文章能够帮你解决PHP实现的Redis多库选择功能单例类所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。