Redis.php 728 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. //统一业务状态码 具体错误码再订
  3. namespace app\common;
  4. class Redis
  5. {
  6. private static $_instance = null; //静态实例
  7. private function __construct(){ //私有的构造方法
  8. self::$_instance = new \Redis();
  9. $config = config("redis"); // redis配置信息
  10. self::$_instance->connect($config['host'],$config['port']);
  11. if(isset($config['password'])){
  12. self::$_instance->auth($config['password']);
  13. }
  14. }
  15. //获取静态实例
  16. public static function getRedis()
  17. {
  18. if(!self::$_instance){
  19. new self;
  20. }
  21. return self::$_instance;
  22. }
  23. /*
  24. * 禁止clone
  25. */
  26. private function __clone()
  27. {}
  28. }