diff --git a/ThinkPHP/Library/Org/Util/RedisInstance..class.php b/ThinkPHP/Library/Org/Util/RedisInstance..class.php new file mode 100644 index 0000000..092c2c1 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/RedisInstance..class.php @@ -0,0 +1,127 @@ +connect('121.41.88.209', '63789'); + self::Instance()->auth('tinywanredis'); + return static::$_instance; + }catch (\Exception $e){ + return false; + } + } + /** + * Slave1 实例 + * @return null + * @static + */ + public static function SlaveOneInstance() + { + try{ + self::Instance()->connect('121.41.88.209', '63788'); + return static::$_instance; + }catch (\Exception $e){ + return false; + } + } + /** + * Slave2 实例 + * @return null + * @static + */ + public static function SlaveTwoInstance() + { + try{ + self::Instance()->connect('121.41.88.209', '63700'); + return static::$_instance; + }catch (\Exception $e){ + return false; + } + } + /** + * Redis数据库是否连接成功 + * @return bool|string + */ + public static function connect() + { + // 如果连接资源不存在,则进行资源连接 + if (!self::$_connectSource) + { + //@return bool TRUE on success, FALSE on error. + self::$_connectSource = self::Instance()->connect('121.41.88.209', '63789'); + // 没有资源返回 + if (!self::$_connectSource) + { + return 'Redis Server Connection Fail'; + } + } + return self::$_connectSource; + } + /** + * 私有化克隆函数,防止类外克隆对象 + */ + private function __clone() + { + // TODO: Implement __clone() method. + } + /** + * @return \Redis + * @static + */ + public static function test() + { + return 'test'; + } +} \ No newline at end of file