Redis 官方本身不出 Windows 版,只能靠社区移植版或者 WSL / Docker。想让它随开机启动,两条路。
方式一:tporadowski 移植版自带的服务参数
先下载 tporadowski/redis 的 zip,解压到 D:\Redis,目录里应该有:
redis-server.exe
redis-cli.exe
redis.windows.conf
管理员打开 CMD:
cd /d D:\Redis
redis-server.exe --service-install redis.windows.conf --service-name Redis
redis-server.exe --service-start
查看服务状态:
sc query Redis
或者 services.msc 里能看到”Redis”服务。
设置自动启动(默认就是):
sc config Redis start= auto
注意 start= 和 auto 之间必须有空格。
测试:
redis-cli.exe ping
返回 PONG 说明装好了。
停止 / 卸载:
redis-server.exe --service-stop
redis-server.exe --service-uninstall
版本不支持 --service-install 的情况
装某些新版本时(例如 Redis 7.4.x 的某些 Windows 编译版)执行 --service-install 会报:
*** FATAL CONFIG FILE ERROR (Redis 7.4.7) ***
Reading the configuration file, at line 2
>>> 'service-install "redis.conf"'
Bad directive or wrong number of arguments
原因:这个版本不支持 --service-* 参数,redis-server.exe 直接把 --service-install 当成配置项塞进 conf 里解析,才报”错误指令”。
验证一下:
redis-server.exe --help
帮助里没有 --service-install / --service-start 就说明确实不支持。这时候上方式二。
方式二:NSSM 包装(通用兜底)
NSSM 是个通用的 “把任何程序包成 Windows 服务” 的小工具。
管理员 CMD:
nssm install redis
弹出 GUI,填三项:
Path: D:\Redis\redis-server.exe
Startup directory: D:\Redis
Arguments: D:\Redis\redis.conf
保存后:
nssm start redis
日志、重启策略、依赖都能在 NSSM 里配。
验证 Redis 真的在监听
netstat -ano | findstr 6379
看到:
TCP 0.0.0.0:6379 LISTENING
就通了。
一句话总结
有 --service-install 就用它、没有就用 NSSM,Windows 上把 Redis 装成开机服务这事就这两条路。
