简单的redis单例类

/*
自己写着玩
*/
connect(self::REDISHOST,self::REDISPORT);
            if(self::REDISPASWORD){
                self::$_obj->auth(self::REDISPASWORD);
            }
            if($dbname){
                $dbname = (int)$dbname;
                self::$_obj->select($dbname);
            }else{
                self::$_obj->select(self::REDISDBNAME);
            }
        }catch (Exception $e){
            exit($e->getMessage().'
'); } return self::$_obj; } public static function getRedis() { if(!self::$_obj){ self::$_obj = self::connect_redis(); } return self::$_obj; } public function set($key,$value) { if(!empty($key) && !empty($value)){ return self::$_obj->set($key,$value); }else{ return false; } } public function get($key) { if(!empty($key)){ return self::$_obj->get($key); }else{ return false; } } public function exists($key) { if(!empty($key)){ return self::$_obj->exists($key); }else{ return false; } } } //直接调用getredis $redis = redis::getredis(); $redis->get('a');

你可能感兴趣的:(简单的redis单例类)