How can I stop redis-server?

前端 未结 26 1573
清歌不尽
清歌不尽 2020-12-07 06:51

I apparently have a redis-server instance running because when I try to start a new server by entering redis-server, I\'m greeted with the followin

相关标签:
26条回答
  • 2020-12-07 07:02

    Usually this problem arises after I shut down my computer ( or leaving running ) an irregular way.. I believe the port gets stuck open, while the process stops but continues to be bound to the previous port.

    9/10 times the fix can be:

    $ ps aux | grep redis
    
    -> MyUser 2976  0.0  0.0  2459704    320   ??  S    Wed01PM   0:29.94 redis-server *:6379
    
    $ kill 2976
    
    $ redis-server
    

    Good to go.

    0 讨论(0)
  • 2020-12-07 07:02

    The commands below works for me on Ubuntu Server

    $ service /etc/init.d/redis_6379 stop
    $ service /etc/init.d/redis_6379 start
    $ service /etc/init.d/redis_6379 restart
    
    0 讨论(0)
  • 2020-12-07 07:02

    Redis has configuration parameter pidfile (e.g. /etc/redis.conf - check redis source code), for example:

    # If a pid file is specified, Redis writes it where specified at startup
    # and removes it at exit.
    #
    # When the server runs non daemonized, no pid file is created if none is
    # specified in the configuration. When the server is daemonized, the pid file
    # is used even if not specified, defaulting to "/var/run/redis.pid".
    #
    pidfile /var/run/redis.pid
    

    If it is set or could be set, instead of searching for process id (pid) by using ps + grep something like this could be used:

    kill $(cat /var/run/redis.pid)
    

    If required one can make redis stop script like this (adapted default redis 5.0 init.d script in redis source code):

    PIDFILE=/var/run/redis.pid
    if [ ! -f $PIDFILE ]
    then
        echo "$PIDFILE does not exist, process is not running"
    else
        PID=$(cat $PIDFILE)
        echo "Stopping ..."
        kill $PID
        while [ -x /proc/${PID} ]
        do
            echo "Waiting for Redis to shutdown ..."
            sleep 1
        done
        echo "Redis stopped"
    fi
    
    0 讨论(0)
  • 2020-12-07 07:04

    redis-cli shutdown is most effective. The accepted answer does not work for me (OSX Lion). Thanks, @JesseBuesking.

    0 讨论(0)
  • 2020-12-07 07:06

    stop the redis server type in terminal with root user

    sudo service redis-server stop
    

    the message will be display after stop the redis-server

    Stopping redis-server: redis-server.
    

    if you want to start the redis-server type

    sudo service redis-server start
    

    if you want to restart the server type

    sudo service redis-server restart
    
    0 讨论(0)
  • 2020-12-07 07:07

    if you did make install (e.g ubuntu) while installing redis then you can do:

    redis-cli shutdown
    

    as pointed by @yojimbo87 :)

    0 讨论(0)
提交回复
热议问题