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

Opening port: bind: Address already in use

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

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

我的操作系统是Ubuntu 10.04。


当前回答

我的情况是:

/etc/init.d/redismaster stop
/etc/init.d/redismaster start

要找出你的服务名称,你可以运行:

sudo updatedb
locate redis

它会显示你系统中的每一个Redis文件。

其他回答

通常这个问题出现后,我关闭我的电脑(或离开运行)不规则的方式。我认为端口被卡住打开,而进程停止,但继续绑定到前一个端口。

9/10次修复可以是:

$ ps aux | grep redis

-> MyUser 2976  0.0  0.0  2459704    320   ??  S    Wed01PM   0:29.94 redis-server *:6379

$ kill 2976

$ redis-server

准备好了。

要优雅地使用密码关闭特定实例,而不诉诸于暴力杀死命令,请使用:

Redis-cli -p <port> -a <pass> shutdown

root@machine:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       105  0.1  0.0  60552 10772 ?        Ssl  23:27   0:02 redis-server 127.0.0.1:10002
root       111  0.1  0.0  60552 10900 ?        Ssl  23:28   0:02 redis-server 127.0.0.1:10003
root       117  0.1  0.0  60552 10872 ?        Ssl  23:28   0:02 redis-server 127.0.0.1:10004

root@machine:~# redis-cli -p 10002 -a mypassword shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.

root@machine:~# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       111  0.1  0.0  60552 10900 ?        Ssl  23:28   0:02 redis-server 127.0.0.1:10003
root       117  0.1  0.0  60552 10872 ?        Ssl  23:28   0:02 redis-server 127.0.0.1:10004

root@machine:~#

如果有大量的实例,就需要编写一个批处理脚本来循环遍历所有实例,以便主关机。

下面的命令适用于我的Ubuntu服务器

$ service /etc/init.d/redis_6379 stop
$ service /etc/init.d/redis_6379 start
$ service /etc/init.d/redis_6379 restart

另一种方式是:

ps -ef | grep -i 'redis-server'
kill -9 PID owned by redis

适用于*NIX和OSX

Redis-cli shutdown是最有效的。接受的答案不适合我(OSX Lion)。谢谢,@JesseBuesking。