php连接redis
/** * */ class _redis_{ private $redis; private static $connections = array(); //定义一个对象池 private static $servers = array(); //定义redis配置文件 public static function addServer($conf){//定义添加redis配置方法 foreach ($conf as $name => $data){ self::$servers[$name]=$data; } } public static function getRedis($name,$select = 0){ //两个参数要连接的服务器KEY,要选择的库 if(!array_key_exists($name,self::$connections)){ //判断连接池中是否存在 $redis = new \Redis(); $redis->connect(self::$servers[$name][0],self::$servers[$name][1]); self::$connections[$name]=$redis; if(isset(self::$servers[$name][2]) && self::$servers[$name][2]!=""){ self::$connections[$name]->auth(self::$servers[$name][2]); } } self::$connections[$name]->select($select); return self::$connections[$name]; } }
相关推荐
savorTheFlavor 2020-10-23
王道革 2020-11-25
wangdonghello 2020-11-03
Langeldep 2020-11-16
chenhualong0 2020-11-16
聚合室 2020-11-16
koushr 2020-11-12
MRFENGG 2020-11-11
guoyanga 2020-11-10
fackyou00 2020-11-10
Orangesss 2020-11-03
dongCSDN 2020-10-31
rainandtear 2020-10-30
Quietboy 2020-10-30
liuyulong 2020-10-29
fansili 2020-10-29
温攀峰 2020-10-23
jackbon 2020-10-19