1234567891011121314151617181920212223242526272829303132 |
- <?php
- //统一业务状态码 具体错误码再订
- namespace app\common;
- class Redis
- {
- private static $_instance = null; //静态实例
- private function __construct(){ //私有的构造方法
- self::$_instance = new \Redis();
- $config = config("redis"); // redis配置信息
- self::$_instance->connect($config['host'],$config['port']);
- if(isset($config['password'])){
- self::$_instance->auth($config['password']);
- }
- }
- //获取静态实例
- public static function getRedis()
- {
- if(!self::$_instance){
- new self;
- }
- return self::$_instance;
- }
- /*
- * 禁止clone
- */
- private function __clone()
- {}
- }
|