3

I terminated the redis server using SHUTDOWN from redis-cli. Now the prompt shows 'not connected>'.

The only way I found to restart the server was to exit the redis-cli prompt and then do a restart of the redis service.

My question is, is there any way to restart the server from the redis-cli prompt using any redis commands WITHOUT EXITING the redis-cli prompt?

Adarsh Philip
  • 69
  • 1
  • 1
  • 7

2 Answers2

2

While you don't have to exit the cli, the server cannot be restarted from it once it is shut down.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • Thanks! So the only way to restart the server is to exit the redis-cli and do a $ sudo service redis-cli restart? – Adarsh Philip Apr 01 '16 at 10:39
  • 1
    You don't have to exit the cli - you can simply open another shell session. Once the server's up, back in the cli's `not connected>` prompt type any valid command to reconnect to the server (e.g. `PING`). – Itamar Haber Apr 01 '16 at 21:29
  • That saved me a lot of research time, which evidently would have lead to nothing. Already had searched a lot! Thank you so much! – Adarsh Philip Apr 05 '16 at 04:37
0

i agree Itamar Haber answer and i will uncover the details

after the server restart,if you type any command in this 'not connected>',the redis-cli will attempt connect again if send command failed.

while (1) {
        config.cluster_reissue_command = 0;
        if (cliSendCommand(argc,argv,repeat) != REDIS_OK) {
            cliConnect(1);//try to connect redis server if sendcommand failed

            if (cliSendCommand(argc,argv,repeat) != REDIS_OK) {//after try to connect,send commend again
                cliPrintContextError();
                return REDIS_ERR;
            }
         }
    }

after redis-server restart successfully,it will listen socket event,if socket connect occur,server will accept connect at here

     void acceptTcpHandler(aeEventLoop *el, int fd, void *privdata, int mask) {
                ......some code.......
    while(max--) {
        cfd = anetTcpAccept(server.neterr, fd, cip, sizeof(cip), &cport);//accept connect
        if (cfd == ANET_ERR) {
            if (errno != EWOULDBLOCK)
                serverLog(LL_WARNING,
                    "Accepting client connection: %s", server.neterr);
            return;
        }
        serverLog(LL_VERBOSE,"Accepted %s:%d", cip, cport);
        acceptCommonHandler(cfd,0,cip);
    }
}
王奕然
  • 3,891
  • 6
  • 41
  • 62