我显然有一个redis-server实例正在运行,因为当我试图通过输入redis-server启动一个新服务器时,我受到以下欢迎:

Opening port: bind: Address already in use

我不知道如何停止这个服务器,并启动一个新的。

当我在CLI中输入时,是否有任何命令可以附加到redis-server ?

我的操作系统是Ubuntu 10.04。


当前回答

在MacOSX上,

这对我来说很管用

/etc/init.d/redis restart

/etc/init.d/redis stop

/etc/init.d/redis start

其他回答

在MacOSX上,

这对我来说很管用

/etc/init.d/redis restart

/etc/init.d/redis stop

/etc/init.d/redis start

以下是我在MAC上的工作

 ps aux | grep 'redis-server' | awk '{print $2}' | xargs sudo kill -9

Redis有配置参数pidfile(例如/etc/redis.conf -检查Redis源代码),例如:

# 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

如果它已经设置或可以设置,可以使用ps + grep来搜索进程id (pid),而不是像这样使用:

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

如果需要,一个可以使redis停止脚本像这样(改编默认redis 5.0初始化。D脚本在redis源代码):

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

对于OSX,我创建了以下别名用于启动和停止redis(安装在Homebrew中):

alias redstart='redis-server /usr/local/etc/redis/6379.conf'
alias redstop='redis-cli -h 127.0.0.1 -p 6379 shutdown'

这对当地的发展很有帮助!

Homebrew现在有了Homebrew服务,可以用来启动、停止和重新启动服务。homebrew-services

Brew服务在运行时自动安装。

brew services start|run redis 
brew services stop redis
brew services restart redis

如果您使用run,那么它将不会在登录(或引导)时启动。Start将启动redis服务,并在登录和启动时添加它。

SystemD, Ubuntu 16.04:

$ sudo systemctl is-active redis-server
active

$ sudo systemctl is-enabled redis-server
enabled

$ sudo systemctl disable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable redis-server
Removed /etc/systemd/system/redis.service.

$ sudo systemctl stop redis-server