Redis.php 673 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Com;
  3. use EasySwoole\EasySwoole\Config;
  4. class Redis
  5. {
  6. private static $instance;
  7. protected $connect; //Redis连接实例
  8. static function getInstance(){
  9. if(!isset(self::$instance)){
  10. self::$instance = new static();
  11. }
  12. return self::$instance;
  13. }
  14. function __construct()
  15. {
  16. $db_config = Config::getInstance()->getConf('REDIS');
  17. $this->connect = new \Redis();
  18. $this->connect->connect($db_config['host'], $db_config['port']); //连接Redis
  19. $this->connect->auth($db_config['auth']); //密码验证
  20. }
  21. public function getConnect(){
  22. return $this->connect;
  23. }
  24. }