Win64版的Redis由微软团队(MSOpenTech)开发,其源代码托管Github账号这里。目前,MSOpenTech给出的最新版本里已经不再支持Win32 Redis。
Redis下载,地址:https://github.com/MSOpenTech/redis/releases,例如下载Redis-x64-2.8.2104.zip,下载完解压到系统盘(D盘)即可,比如解压到D:\redis64-2.8.2104。
Redis安装,把Redis注册为系统服务进程,以方便管理和使用,但非必须,打开cmd,进入D:\redis64-2.8.2104目录,然后运行 :
redis-server --service-install redis.windows.conf --loglevel verbose
如果注册了,则可以运行以下命令启动
redis-server --service-start
非注册的情况可以运行以下命令启动:
redis-server redis.windows.conf
注册方式停止服务命令:
redis-server --service-stop
非注册方式可以直接Ctrl+c退出
移出注册的redis服务命令:
redis-server --service-uninstall
客户端访问测试,cmd一个新的窗口,cd进入redis所在根目录(D:\redis64-2.8.2104),通过以下命令访问:
redis-cli -h 127.0.0.1 -p 6379
以上命令指定了主机地址和端口号(注意空格隔开),如果不指定的话(直接输入redis-cli命令),则使用默认的主机地址(127.0.0.1)和端口号(6379)。
使用redis:
set sKey 'Redis start on win64' append sKey ' ,I am CJ.' get sKey keys *
Windows下使用redis会遇到的问题:
The Windows version of Redis allocates a memory mapped heap for sharing with the forked process used for persistence operations. In order to share this memory, Windows allocates from the system paging file a portion equal to the size of the Redis heap. At this time there is insufficient contiguous free space available in the system paging file for this operation (Windows error 0x5AF). To work around this you may either increase the size of the system paging file, or decrease the size of the Redis heap with the --maxheap flag. Sometimes a reboot will defragment the system paging file sufficiently for this operation to complete successfully. Please see the documentation included with the binary distributions for more details on the --maxheap flag. Redis can not continue. Exiting.
引起该问题的主要原因是maxheap设置的问题。手动设定maxheap小一些,不能太小,至少大于1MB,打开redis.windows.conf文件,找到maxheap配置文本处添加如下一行即可:
maxheap 4294967296此外heapdir参数的配置也很重要,可以设置为 D:\redis64-2.8.2104\heapdir。