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

Opening port: bind: Address already in use

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

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

我的操作系统是Ubuntu 10.04。


当前回答

以下是我在MAC上的工作

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

其他回答

MacOSX -它工作了:)

步骤1:找到之前运行的Redis服务器

ps auxx | grep redis-server

步骤2:通过查找PID(进程ID) - Redis Sever来杀死特定的进程

kill -9 PID

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

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:~#

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

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

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

一个更干净、更可靠的方法是进入redis-cli,然后输入shutdown

在redis-cli中,输入help @server,你会在列表底部看到:

SHUTDOWN - summary:同步保存数据集到磁盘,然后 从:0.07开始关闭服务器

如果你在终端中运行一个redis-server实例,你会看到:

User requested shutdown...
[6716] 02 Aug 15:48:44 * Saving the final RDB snapshot before exiting.
[6716] 02 Aug 15:48:44 * DB saved on disk
[6716] 02 Aug 15:48:44 # Redis is now ready to exit, bye bye...