Ver código fonte

所有redis需要设置密码,选择数据库

lizhen_gitee 1 ano atrás
pai
commit
d89c22b7e0

+ 180 - 0
Party.php

@@ -75,6 +75,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $where = [];
         $where["user_id"] = $user_id;
@@ -187,6 +193,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
 
             // 更新redis  加入缓存
             $redPartyInfo = $redis->get($this->roomTypeArr[$room_type] . "_" . $partyInfo["id"]);
@@ -219,6 +231,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $redis->zRem($this->roomTypeArr[$room_type] . "Rank", $party_id);
             $redis->del($this->roomTypeArr[$room_type] . "_" . $party_id);
             $this->success("删除成功!");
@@ -246,6 +264,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type] . "Rank", 0, -1, true);
         $partyModel = new \app\common\model\Party();
         if (!$redisPartyRankList) {
@@ -294,6 +318,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $res = [];
         // 获取今天
@@ -349,6 +379,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         // 更新热度
         $redis->zIncrBy($this->roomTypeArr[$room_type] . "Rank", $party_hot, $party_id);
         return $this->success("更新成功!");
@@ -395,6 +431,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redisData = $redis->get($this->roomTypeArr[$room_type] . "_" . $party_id);
         if ($redisData) {
             $partyInfo = json_decode($redisData, true);
@@ -430,6 +472,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $res = $redis->hGetAll("online_" . $party_id);
         $user_ids = [];
@@ -455,6 +503,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redis->zAdd("party_user_" . $party_id, $this->auth->u_id, $user_id);
 
         // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
@@ -552,6 +606,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
         $lsetList = [];
@@ -584,6 +644,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redis->zRem("party_user_" . $party_id, $user_u_id);
 
         return $this->success("退出成功!", []);
@@ -600,6 +666,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $userids = $redis->zRange("party_user_" . $party_id, 0, -1, true);
         $useridArr = [];
         if ($userids) foreach ($userids as $k => $v) $useridArr[$v] = $k; // 因为array_slip 不能交换数字啊
@@ -627,6 +699,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $partyModel = new \app\common\model\Party();
         $data = [];
@@ -666,6 +744,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $partycellectionModel = new \app\common\model\PartyCellection();
         // 添加记录
@@ -711,6 +795,12 @@ class Party extends Common
 //            $redis = new Redis();
 //            $redisconfig = config("redis");
 //            $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            /*if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }*/
 //            // 获取本周第一天
 //            $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
 //            // 获取redis 中 用户排行榜前五名
@@ -836,6 +926,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $partyInfo = $redis->get($this->roomTypeArr[$room_type] . "_" . $party_id);
             if ($partyInfo) {
                 $partyInfo = json_decode($partyInfo, true);
@@ -892,6 +988,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $data = [];
         $data["user_id"] = $user_id;
@@ -927,6 +1029,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
 
         $hget = $redis->hGetAll("party_manage_" . $party_id);
@@ -960,6 +1068,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $res = $redis->hDel("party_manage_" . $party_id, $id . "-" . $item);
         if ($res !== false) {
             $this->success("移除成功!", $res);
@@ -992,6 +1106,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $partyInfo = $redis->get($this->roomTypeArr[$room_type] . "_" . $party_id);
             if ($partyInfo) {
                 $partyInfo = json_decode($partyInfo, true);
@@ -1025,6 +1145,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data = unserialize($redis->hGet("party_lineup", $party_id));
         $data[$userid]["user_id"] = $userInfo['id'];
         $data[$userid]["avatar"] = $userInfo['avatar'];
@@ -1060,6 +1186,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data = unserialize($redis->hGet("party_lineup", $party_id));
         if ($data && $is_empty != 1) {
             foreach ($data as $k => $v) {
@@ -1089,6 +1221,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data = $redis->hGet("party_lineup", $party_id);
         $dataArr = unserialize($data);
         $datas = [];
@@ -1127,6 +1265,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $partyInfo = $redis->get($this->roomTypeArr[$room_type] . "_" . $party_id);
         if ($partyInfo) {
             $partyInfo = json_decode($partyInfo, true);
@@ -1334,6 +1478,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             // 事务处理余额与记录信息
             $userjewellogModel = new \app\common\model\UserJewelLog();
             $usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
@@ -1589,6 +1739,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $redis->zAdd($this->roomTypeArr[$room_type] . "Rank", $partyInfo['party_hot'], $partyInfo["id"]);
 
             // 更新redis  加入缓存
@@ -1623,6 +1779,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 获取本周第一天
         $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
@@ -1665,6 +1827,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 获取用户魅力值
         $users = $redis->zRange("hourCharm_" . $party_id, 0, -1, true);
@@ -1696,6 +1864,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $res = $redis->del("hourCharm_" . $party_id);
         $this->success("操作成功!");
 
@@ -1730,6 +1904,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         // 获取所有派对ID
         $party_ids = \app\common\model\Party::where(["status" => 1])->column("id");
         // 获取数据

+ 6 - 0
application/admin/controller/party/Party.php

@@ -132,6 +132,12 @@ class Party extends Backend
                         $redis = new Redis();
                         $redisconfig = config("redis");
                         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                        if ($redisconfig['redis_pwd']) {
+                            $redis->auth(config('redis_pwd'));
+                        }
+                        if($redisconfig['redis_selectdb'] > 0){
+                            $redis->select(config('redis_selectdb'));
+                        }
                         $partyInfo = $redis->get($roomTypeArr[$room_type]."_".$party_id);
                         if($partyInfo) {
                             $partyInfo = json_decode($partyInfo,true);

+ 12 - 0
application/api/controller/Egg.php

@@ -77,6 +77,12 @@ class Egg extends Api
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             for($i=1;$i<=$num;$i++) {
                 $val = date("YmdHis").$i;
                 $redis->lpush("hammer_num_".$user_id,$val);
@@ -133,6 +139,12 @@ class Egg extends Api
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 //        if($redis->lLen("hammer_num_".$user_id) < $num) $this->error("小金锤数量不足!");
 
         $do_no = date("YmdHis").rand(10000,99999);

+ 6 - 0
application/api/controller/Gatewayworker.php

@@ -87,6 +87,12 @@ class Gatewayworker extends Api
 //            $redis = new Redis();
 //            $redisconfig = config("redis");
 //            $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        /*if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }*/
 //            foreach($party_id as $v) {
 //                $redis->del("hourCharm_".$v);
 //            }

+ 6 - 0
application/api/controller/Guild.php

@@ -468,6 +468,12 @@ class Guild extends Api
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             // 获取成员用户信息
             $memberuserInfo = \app\common\model\User::field("id,avatar,nickname,gender,level")->find($member_user_id);
             $data = [];

+ 44 - 1
application/api/controller/Live.php

@@ -150,6 +150,12 @@ class Live extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
 
         if(!$sqlLiveInfo) { // sql中不存在直播间信息
@@ -224,6 +230,12 @@ class Live extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redisLiveRankList = $redis->zRange("liveRank",$start,$end);
         $liveModel = new \app\common\model\Live();
         if(!$redisLiveRankList) {
@@ -272,6 +284,12 @@ class Live extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $res = [];
         // 获取本周第一天
@@ -313,6 +331,12 @@ class Live extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         // 更新热度
         $redis->zIncrBy("liveRank", $live_hot, $live_id);
         return $this->success("更新成功!");
@@ -397,6 +421,12 @@ class Live extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             // 获取本周第一天
             $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
             // 获取redis 中 用户排行榜前五名
@@ -636,6 +666,12 @@ class Live extends Common
                 $redis = new Redis();
                 $redisconfig = config("redis");
                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                if ($redisconfig['redis_pwd']) {
+                    $redis->auth(config('redis_pwd'));
+                }
+                if($redisconfig['redis_selectdb'] > 0){
+                    $redis->select(config('redis_selectdb'));
+                }
 
                 // 获取本周第一天
                 $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
@@ -672,7 +708,14 @@ class Live extends Common
      */
     public function updateLiveInfo() {
         $redis = new Redis();
-        $redis->connect(config("redis")["host"], config("redis")["port"]);
+        $redisconfig = config("redis");
+        $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         // 获取直播间热度信息
         $redisLiveRankList = $redis->zRevRange("liveRank",0,-1,true);
         $liveModel = new \app\common\model\Live();

+ 188 - 1
application/api/controller/Party.php

@@ -77,6 +77,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $where = [];
         $where["user_id"] = $user_id;
@@ -200,6 +206,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
 
             // 更新redis  加入缓存
             $redPartyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$partyInfo["id"]);
@@ -231,6 +243,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $redis->zRem($this->roomTypeArr[$room_type]."Rank",$party_id);
             $redis->del($this->roomTypeArr[$room_type]."_".$party_id);
             $this->success("删除成功!");
@@ -257,6 +275,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
 
         $partyModel = new \app\common\model\Party();
@@ -306,6 +330,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $res = [];
         // 获取今天
@@ -361,6 +391,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         // 更新热度
         $redis->zIncrBy($this->roomTypeArr[$room_type]."Rank", $party_hot, $party_id);
         return $this->success("更新成功!");
@@ -407,6 +443,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redisData = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
         if($redisData) {
             $partyInfo = json_decode($redisData,true);
@@ -441,6 +483,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $res = $redis->hGetAll("online_".$party_id);
         $user_ids = [];$userList = [];
@@ -464,6 +512,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redis->zAdd("party_user_".$party_id,$this->auth->u_id,$user_id);
 
         // 判断当前用户是否存在在直播间通过切换过来的
@@ -585,6 +639,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 判断当前用户是否被该房间设置限制 //项目:1=房管,2=禁言,3=拉黑,4=踢出
         $lsetList = [];
@@ -616,10 +676,17 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
+
         $redis->zRem("party_user_".$party_id,$user_u_id);
 
         // 处理online_party_id
-        $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        //$redis->connect($redisconfig["host"], $redisconfig["port"]);
         $redis->HDel("online_" . $party_id, $this->auth->id);
 
         // 扣除在线用户在房间情况
@@ -660,6 +727,12 @@ class Party extends Common
 //        $redis = new Redis();
 //        $redisconfig = config("redis");
 //        $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        /*if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }*/
 //        $userids = $redis->zRange("party_user_".$party_id,0,-1,true);
 //        $useridArr = [];
 //        if($userids)foreach($userids as $k => $v)  $useridArr[$v] = $k; // 因为array_slip 不能交换数字啊
@@ -686,6 +759,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $partyModel = new \app\common\model\Party();
         $data = [];
@@ -724,6 +803,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $partycellectionModel = new \app\common\model\PartyCellection();
         // 添加记录
@@ -768,6 +853,12 @@ class Party extends Common
 //            $redis = new Redis();
 //            $redisconfig = config("redis");
 //            $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            /*if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }*/
 //            // 获取本周第一天
 //            $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
 //            // 获取redis 中 用户排行榜前五名
@@ -891,6 +982,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
             if($partyInfo) {
                 $partyInfo = json_decode($partyInfo,true);
@@ -950,6 +1047,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         $data = [];
         $data["user_id"] = $user_id;
@@ -984,6 +1087,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
 
         $hget=$redis->hGetAll("party_manage_".$party_id);
@@ -1016,6 +1125,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $res = $redis->hDel("party_manage_".$party_id,$id."-".$item);
         if($res !== false) {
             $this->success("移除成功!",$res);
@@ -1047,6 +1162,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
             if($partyInfo) {
                 $partyInfo = json_decode($partyInfo,true);
@@ -1079,6 +1200,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data = unserialize($redis->hGet("party_lineup",$party_id));
         $data[$userid]["user_id"] = $userInfo['id'];
         $data[$userid]["avatar"] = $userInfo['avatar'];
@@ -1113,6 +1240,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data=unserialize($redis->hGet("party_lineup",$party_id));
         if($data && $is_empty != 1) {
             foreach($data as $k => $v) {
@@ -1141,6 +1274,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data = $redis->hGet("party_lineup",$party_id);
         $dataArr = unserialize($data);
         $datas = [];
@@ -1177,6 +1316,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $partyInfo = $redis->get($this->roomTypeArr[$room_type]."_".$party_id);
         if($partyInfo) {
             $partyInfo = json_decode($partyInfo,true);
@@ -1389,6 +1534,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             // 事务处理余额与记录信息
             $userjewellogModel = new \app\common\model\UserJewelLog();
             $usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
@@ -1651,6 +1802,12 @@ class Party extends Common
             $redis = new Redis();
             $redisconfig = config("redis");
             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+            if ($redisconfig['redis_pwd']) {
+                $redis->auth(config('redis_pwd'));
+            }
+            if($redisconfig['redis_selectdb'] > 0){
+                $redis->select(config('redis_selectdb'));
+            }
             $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $partyInfo['party_hot'], $partyInfo["id"]);
 
             // 更新redis  加入缓存
@@ -1684,6 +1841,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 获取本周第一天
         $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
@@ -1725,6 +1888,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 获取用户魅力值
         $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
@@ -1756,6 +1925,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         if ($userId) {
             $redis->zRem("hourCharm_" . $party_id, $userId);
@@ -1793,6 +1968,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         // 获取所有派对ID
         $party_ids = \app\common\model\Party::where(["status"=>1])->column("id");
         // 获取数据
@@ -1829,6 +2010,12 @@ class Party extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
 //        $redis->del("online_" . 3);die;
 //        $redis->hSet("online_" . 3, 4, 4);die;

+ 42 - 0
application/api/controller/Tenim.php

@@ -430,6 +430,12 @@ exit;
                 $redis = new Redis();
                 $redisconfig = config("redis");
                 $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                if ($redisconfig['redis_pwd']) {
+                    $redis->auth(config('redis_pwd'));
+                }
+                if($redisconfig['redis_selectdb'] > 0){
+                    $redis->select(config('redis_selectdb'));
+                }
                 $redis->HDel("online_".$v["GroupId"],$user_id);
             }
             // 强制下麦
@@ -451,6 +457,12 @@ exit;
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $redisData = $redis->get("party_".$party_id);
         if(!$redisData) {
             return true;
@@ -476,6 +488,12 @@ exit;
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $data=unserialize($redis->hGet("party_lineup",$party_id));
         // 更改红点排麦数量
         $num = 0;
@@ -551,6 +569,12 @@ exit;
                     $redis = new Redis();
                     $redisconfig = config("redis");
                     $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                    if ($redisconfig['redis_pwd']) {
+                        $redis->auth(config('redis_pwd'));
+                    }
+                    if($redisconfig['redis_selectdb'] > 0){
+                        $redis->select(config('redis_selectdb'));
+                    }
                     $livingUserPartyId = $redis->hGet("livingUser", $info["To_Account"]);
                     if ($livingUserPartyId) {
                         // 扣除在线用户在房间情况
@@ -574,6 +598,12 @@ exit;
                             $redis = new Redis();
                             $redisconfig = config("redis");
                             $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                            if ($redisconfig['redis_pwd']) {
+                                $redis->auth(config('redis_pwd'));
+                            }
+                            if($redisconfig['redis_selectdb'] > 0){
+                                $redis->select(config('redis_selectdb'));
+                            }
                             $redis->HDel("online_".$v["GroupId"],$info["To_Account"]);
 
                             // 更新麦位前四
@@ -616,6 +646,12 @@ exit;
 //                $redis = new Redis();
 //                $redisconfig = config("redis");
 //                $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                /*if ($redisconfig['redis_pwd']) {
+                    $redis->auth(config('redis_pwd'));
+                }
+                if($redisconfig['redis_selectdb'] > 0){
+                    $redis->select(config('redis_selectdb'));
+                }*/
 //                $members = $input["NewMemberList"];
 //                if($members) foreach($members as $k => $v) {
 //                    $redis->hSet("online_".$input["GroupId"],$v["Member_Account"],$v["Member_Account"]);
@@ -641,6 +677,12 @@ exit;
 //                $redis = new Redis();
 //                $redisconfig = config("redis");
 //                $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                /*if ($redisconfig['redis_pwd']) {
+                    $redis->auth(config('redis_pwd'));
+                }
+                if($redisconfig['redis_selectdb'] > 0){
+                    $redis->select(config('redis_selectdb'));
+                }*/
 //                $members = $input["ExitMemberList"];
 //                if($members) foreach($members as $k => $v) {
 //                    $redis->HDel("online_".$input["GroupId"],$v["Member_Account"]);

+ 12 - 0
application/api/controller/Tentrtc.php

@@ -39,6 +39,12 @@ class Tentrtc extends Api
                     $redis = new Redis();
                     $redisconfig = config("redis");
                     $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                    if ($redisconfig['redis_pwd']) {
+                        $redis->auth(config('redis_pwd'));
+                    }
+                    if($redisconfig['redis_selectdb'] > 0){
+                        $redis->select(config('redis_selectdb'));
+                    }
 
                     $userId = $aRequest['EventInfo']['UserId'];
                     $redis->hSet("online_" . $roomId, $userId, $userId);
@@ -72,6 +78,12 @@ class Tentrtc extends Api
                     $redis = new Redis();
                     $redisconfig = config("redis");
                     $redis->connect($redisconfig["host"], $redisconfig["port"]);
+                    if ($redisconfig['redis_pwd']) {
+                        $redis->auth(config('redis_pwd'));
+                    }
+                    if($redisconfig['redis_selectdb'] > 0){
+                        $redis->select(config('redis_selectdb'));
+                    }
 
                     $userId = $aRequest['EventInfo']['UserId'];
                     $redis->HDel("online_" . $roomId, $userId);

+ 12 - 0
application/api/controller/Usercenter.php

@@ -73,6 +73,12 @@ class UserCenter extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $livingUserPartyId = $redis->hGet("livingUser", $user_id);
 
         $userInfo['party_info'] = json([]);
@@ -694,6 +700,12 @@ class UserCenter extends Common
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         // 获取本周第一天
         $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));

+ 6 - 0
application/common/controller/Api.php

@@ -379,6 +379,12 @@ class Api
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         $check = $redis->exists($key);
         if ($check) {
             $redis->incr($key);

+ 6 - 0
application/common/model/Live.php

@@ -24,6 +24,12 @@ class Live extends Model
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
 
         if(is_array($live_id)) {
             $redisLiveInfo = [];

+ 6 - 0
application/common/model/Party.php

@@ -26,6 +26,12 @@ class Party extends Model
         $redis = new Redis();
         $redisconfig = config("redis");
         $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth(config('redis_pwd'));
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select(config('redis_selectdb'));
+        }
         if(!is_array($party_id)) {
             return [];
         }

+ 2 - 0
application/config.php

@@ -307,6 +307,8 @@ return [
         'host'     => '127.0.0.1',
         // 端口
         'port'      => 6379,
+        'redis_pwd' => 123456,
+        'redis_selectdb' => 8,
     ],
     'cos'                  => [
         // // 链接