首页 > 其他 > 详细

设计模式案例(个人笔记)

时间:2018-09-10 10:20:09      阅读:162      评论:0      收藏:0      [点我收藏+]

一、单例模式,示例:

<?php

class Predis{

  public $redis = "";

  private static $_instance = null;

  public static function getInstance() {

    if(empty(self::$_instance)) {

      self::$_instance = new self();

    }

    return self::$_instance;

  }

 

  private function __construct() {

    $this->redis = new \Redis();

    $result = $this->redis->connect(config(‘redis.host‘), config(‘redis.port‘), config(‘redis.timeOut‘));

    if($result === false) {

      throw new \Exception(‘redis connect error‘);

    }

  }

}

设计模式案例(个人笔记)

原文:https://www.cnblogs.com/zhengchuzhou/p/9617279.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!