PHP RedisSingleton

WBOY
Release: 2016-06-23 13:06:04
Original
999 people have browsed it

<?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 />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template