Adarsh Philip
Adarsh Philip

Reputation: 69

Redis-cli command to restart the redis server

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?

Upvotes: 3

Views: 16712

Answers (2)

王奕然
王奕然

Reputation: 4049

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);
    }
}

Upvotes: 0

Itamar Haber
Itamar Haber

Reputation: 49942

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

Upvotes: 2

Related Questions