Redis下载地址:https://github.com/MicrosoftArchive/redis/releases
1、打开一个 cmd 窗口,切换到 redis 目录运行 redis-server.exe redis.windows.conf
2、这时候另启一个cmd窗口,原来的不要关闭,切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379
设置键值对 set myKey abc
取出键值对 get myKey
3、设置Redis服务
上面虽然启动了redis,但是只要一关闭cmd窗口,redis就会消失,所以要把redis设置成windows下的服务。
设置服务命令:redis-server --service-install redis.windows-service.conf --loglevel verbose
卸载服务:redis-server --service-uninstall
开启服务:redis-server --service-start
停止服务:redis-server --service-stop
PS:在开启服务时,发生错误# Redis service failed to start.
原因:是配置文件的问题,试着查看配置文件redis.windows-service.conf,会发现下面一段话:
On Windows, daemonize and pidfile are not supported.
However, you can run redis as a Windows service,and specify a logfile.
The logfile will contain the pid.
查询logfile配置,发现为空,在redis目录下新建logfile文件并将其写入配置文件中,即可成功。