连接长时间暂停

连接长时间暂停

服务器redis正在不同的网络命名空间中运行。我尝试将客户端连接到服务器redis,它一直在等待但没有得到响应,已经几个小时了。

客户端代码:

int main(){

        // ***** Pipeline *****
        auto redis = Redis("tcp://192.168.122.50:6379");
        // Create a pipeline.
//      auto pipe = redis.pipeline(false);
        sleep(5);
        int ep = 1;
    while(true){
cout<<"========================"<<ep++<<"==================================================\n";


        auto pipe = redis.pipeline(false);

        for(int i=1; i<=1000; i++){
            string s = to_string(i);
            if(i%2 == 1){
                pipe.set(s, s);
            }
            else {
                string st = to_string(i-1);
                pipe.get(st);       
            }
        }

        auto pipe_replies = pipe.exec();

        time += duration;    
        mntime = min(duration, mntime);  
        mxtime = max(duration, mxtime); 
        cout<<"RESULTS\n";
        
        for (int i=1; i<=1000; i++) {
           if (i%2 == 1) {
               auto set_result = pipe_replies.get<bool>(i-1);
            cout<<set_result<<"\n";
           } else {
              OptionalString get_result = pipe_replies.get<OptionalString>(i-1);
              if (get_result)
              cout << *get_result << endl;  
             else
              cout << "key does not exist" << endl;
                
          }
        }   

//cout<<"============================================================================\n";
            
        pipe.discard();
    }

终端输出:

secondaryvm@secondaryvm:~/tests$ ./hclient
========================1==================================================

已经一个小时了,它仍然在等待,所以我用它进行了分析tcpdump是 tcp 流输出tcpdump。我还尝试 ping redis 服务器正在运行的端口,发现它是开放的。

root@secondaryvm:/home/secondaryvm/tests# nmap -p 6379 192.168.122.50

Starting Nmap 7.60 ( https://nmap.org ) at 2020-12-30 16:26 IST
Nmap scan report for 192.168.122.50
Host is up (0.000050s latency).

PORT     STATE SERVICE
6379/tcp open  redis
MAC Address: FE:2D:4A:25:55:EE (Unknown)

这里发生了什么?以及如何预防?

相关内容