RedisClient, single-instance php code
Set ('xxxxx', 'good'); * $ ret = $ redis-> get ('xxxxx '); **/class RedisCli {private static $ _ instance = array (); private $ _ redis = false;/*** Singleton model, constructor */public static function getInstance ($ conf_dir = '/xxx/redis. conf. php ', $ serverName = 'master') {if (isset (self: $ _ instance [$ serverName]) {return self :: $ _ instance [$ serverName];} require_once ($ conf_dir); if (! Isset ($ redis_conf [$ serverName]) {throw new Exception ("param serverName Or redis config error... ") ;}$ conf = $ redis_conf [$ serverName]; if (! Class_exists ('redis ') {throw new Exception ("Class Redis not exists, please install the php Redis extension... ");} if (isset ($ conf ['host']) & isset ($ conf ['port']) & isset ($ conf ['passwd']) & isset ($ conf ['timeout']) {self ::$ _ instance [$ serverName] = new self ($ conf ['host'], $ conf ['port'], $ conf ['passwd'], $ conf ['timeout']); return self: $ _ instance [$ serverName];} return false;}/*** private, Singleton model, disable external construction */p Rivate function _ construct ($ host, $ port, $ passwd, $ timeout) {$ this-> _ redis = new Redis (); if ($ this-> _ redis-> connect ($ host, $ port, $ timeout) {if (! Empty ($ passwd) {$ this-> _ redis-> auth ($ passwd) ;}}/ *** private, Singleton model, clone prohibited */private function _ clone () {}/*** public, call object function */public function _ call ($ method, $ args) {if (! $ This-> _ redis |! $ Method) {return false;} if (! Method_exists ($ this-> _ redis, $ method) {throw new Exception ("Class RedisCli not have method ($ method )");} return call_user_func_array (array ($ this-> _ redis, $ method), $ args) ;}}?>