Skip to content

Commit

Permalink
开启redis单例模式
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao committed Feb 19, 2016
1 parent 57896cc commit 53fadaf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/SRedis.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function __construct(){
}
private static $_config;
private static $_rc;
private static $_instances=array();

static function setConfigFile($file){
self::$_config = $file;
Expand All @@ -49,6 +50,11 @@ static function getConfig($zone=null,$type="host"){
* @return array
*/
static function useConfig($zone,$type="host"){
$key = $zone.":".$type;
if(isset(self::$_instances[$key])){
self::$_rc = self::$_instances[$key];
return self::$_rc;
}
$hosts=array();
$options=array();
$config = self::getConfig($zone,$type);
Expand All @@ -69,7 +75,7 @@ static function useConfig($zone,$type="host"){
}
}
}
self::$_rc = new RedisArray($hosts,$options);
return self::$_rc = self::$_instances[$key] = new RedisArray($hosts,$options);
}
public function __call($name,$args){
return call_user_func_array(array(self::$_rc,$name),$args);
Expand Down

0 comments on commit 53fadaf

Please sign in to comment.