環(huán)境:window的java服務突雪,虛擬機centos7的redis集群怀骤,在window上啟動服務連接redis集群
redisson版本為3.7.1 redis7.0
一蛀序、配置沒問題畜隶,包括主從和sentinel
問題:無法連接到redis(can not connect to rediss://ip:2369.....關鍵行會標志在Redisson.create(config)方法蒋譬,大概這樣子享钞,是否跟我一樣的問題自己判斷吧)
(1)window再裝了個redis揍诽,然后 在window系統(tǒng)的redis文件執(zhí)行cmd “redis-cli.exe -h redis集群其中一個的ip -p 26379 info” 發(fā)現(xiàn)跟linux執(zhí)行一樣,正常
(2)java寫一個執(zhí)行cmd命令的,直接上代碼暑脆,dddd
public class Test {
? ? public static void main(String [] args){
? ? ? String a =redis文件目錄\\redis-cli.exe -h linux的redis的ip -p 26379 info";
Test test =new Test();
test.execCmdOrder(a);
}
? ? public String execCmdOrder(String cmdCommand) {
? ? ? ? if (StringUtils.isEmpty(cmdCommand)){
? ? ? ? ? ? throw new RuntimeException("需要執(zhí)行的命令不可以為空");
}
? ? ? ? /*if (***其他判斷條件***){
? ? ? ? ? ? throw new RuntimeException("不滿足判斷條件的原因");
}*/
? ? ? ? //組裝cmd 命令
? ? ? ? String cmd= cmdCommand ;
BufferedReader br=null;
Process process=null;
//執(zhí)行命令結(jié)果
? ? ? ? StringBuilder result =null;
try {
? ? ? ? ? ? //執(zhí)行cmd命令
? ? ? ? ? ? process=Runtime.getRuntime().exec(cmd);
//獲取cmd命令的輸出結(jié)果
? ? ? ? ? ? br=new BufferedReader(new InputStreamReader(process.getInputStream()));
result=new StringBuilder();
String tmp;
//組裝命令執(zhí)行結(jié)束后返回值
? ? ? ? ? ? while ((tmp=br.readLine())!=null){
? ? ? ? ? ? ? ? result.append(tmp).append("\n");
}
? ? ? ? ? ? process.waitFor();
} catch (IOException |InterruptedException e) {
? ? ? ? ? ? e.printStackTrace();
}finally {
? ? ? ? ? ? if (br!=null){
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? br.close();
} catch (IOException e) {
? ? ? ? ? ? ? ? ? ? e.printStackTrace();
}
? ? ? ? ? ? }
? ? ? ? ? ? if (process !=null) {
? ? ? ? ? ? ? ? process.destroy();
}
? ? ? ? ? ? System.out.println("執(zhí)行命令結(jié)束以后控制臺返回結(jié)果為 :" +result);
}
? ? ? ? return result.toString();
}
}
上面大部分代碼是百度的交排,自己改命令就行了。
于是結(jié)果就是跟(1)的結(jié)果一樣是正常饵筑,于是看代碼埃篓,點進去關鍵方法,
在這里debug看到了是因為ssl的問題根资。架专。我透
于是
把這的rediss改為redis就好了
于是繼續(xù)。玄帕。部脚。。裤纹。
下一個問題出現(xiàn)了
它會提示commond slaves不合法什么的委刘,確實沒有slaves了啊我redis都7.0了,急了鹰椒,上git看看版本锡移,發(fā)現(xiàn)3.7.1有個文件是4年前的,不太懂這個能不能證明它的年齡漆际,但是馬上改成最新的3.8.0了淆珊。
啟動!失敿榛恪施符!還是一樣的錯誤,再細看錯誤日志
關鍵字句在?Set checkSentinelsList = false to avoid this check這個上面擂找,于是
就行了戳吝,解決!
測試贯涎,通過听哭,暫無發(fā)現(xiàn)什么問題
要問解決的原理,真不懂柬采,百度也沒找到幾個是詳細說redisson的欢唾,不知道是不是我找的姿勢不對
用redisson其實也是為了它實現(xiàn)的鎖
我只是以粗暴的方式解決了這個,希望能給大家?guī)碛杏玫牡胤?/p>