<?php<br /><br />/**<br /> * Created by PhpStorm.<br /> * User: xiongzai<br /> * Date: 2016/5/17<br /> * Time: 16:31<br /> */<br /><br />namespace Think;<br /><br />class RedisSingleton {<br /><br /> public $redis = null;<br /><br /> static protected $ins=null;<br /><br /> final protected function __construct(){<br /> self::setRedis();<br /> }<br /><br /> private function __clone(){}<br /><br /> static public function getInstance(){<br /> if (self::$ins instanceof self) {<br /> return self::$ins;<br /> }<br /> self::$ins=new self();<br /> return self::$ins;<br /> }<br /><br /><br /> private function setRedis(){<br /> try{<br /> $redis = new \Redis();<br /> $redis->connect( C('REDIS_HOST'), C('REDIS_PORT') );<br /> $redis->auth( C('REDIS_AUTH') );<br /> $this->redis = $redis;<br /> unset($redis);<br /> }catch(Exception $e){<br /> echo $e->getMessage().'<br/>';<br /> }<br /> }<br /><br />}<br /><br />