9

Windows 编译安装和使用Redis最新版

 3 years ago
source link: https://last2win.com/2020/11/07/windows-install-redis/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Windows 编译安装和使用Redis最新版 — 浮云的博客

之前一直在Linux上使用Redis,最近需要在Windows上使用Redis。网上找了一圈教程,大部分教程都是用2016年编译的3.2版本的远古版本,有些比较新的教程是在WSL中安装Redis。

但我不想为了一个Redis而安装WSL,毕竟一个完整的操作系统还是占用挺多系统资源的。

于是我想到了在Windows上直接编译Redis,就可以使用Redis的最新版本了。

准备编译工具:MSYS2

因为Redis编译过程中使用了一些Linux的头文件,不能直接用VS的MSVC或者MinGW

我选择了MSYS2,MSYS2有POSIX兼容层,并且也有包管理工具,使用起来比较方便。

下载地址:MSYS2 homepage

下载好后设置代理(如果你的网络很好,不需要设置代理):

export http_proxy='http://127.0.0.1:7890'
export https_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy

安装gcc:

pacman -S make gcc pkg-config

编译和使用Redis

目前Redis最新版本是6.0,下载解压,编译Redis:

wget https://download.redis.io/releases/redis-6.0.9.tar.gz
tar xzf redis-6.0.9.tar.gz
cd redis-6.0.9
make

编译大约需要10分钟,编译完成后启动Redis服务端:

src/redis-server.exe

需要注意的是编译后的exe文件不能直接在Windows上允许,只能在msys2的终端中运行。

在新窗口中启动Redis客户端:

redis-6.0.9/src/redis-cli.exe

测试连接:

127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK