一、Redis 简介
Redis 是一个开源的高性能 Key-Value 数据库,常用于缓存、消息队列、会话管理等场景。
它支持多种数据结构(String、Hash、List、Set、Sorted Set 等),单线程事件驱动,性能非常高。
二、安装方式总览
系统 | 推荐方式 |
---|---|
Windows | 下载微软维护的 Redis for Windows 版本(或 WSL 安装) |
Linux | 用包管理器(yum/apt)或源码编译 |
macOS | 用 Homebrew 安装 |
三、各平台安装步骤
1. Windows 安装
官方 Redis 不再原生支持 Windows,建议用微软维护的移植版或 WSL。
方法 A:使用 Redis for Windows(社区移植版)
- 进入 GitHub 下载地址(microsoft archive 版):
github.com/microsoftar... - 找到最新的
.zip
压缩包,例如:
Redis-x64-3.2.100.zip
- 解压到一个目录,例如
C:\Redis
- 打开 PowerShell,进入目录:
cd C:\Redis redis-server.exe redis.windows.conf
- 再开一个 PowerShell 连接客户端:
redis-cli.exe
输入:set name "hello" get name
方法 B:WSL 安装(推荐)
- 在 Windows 10/11 开启 Windows Subsystem for Linux
- 安装 Ubuntu 子系统:
wsl --install -d Ubuntu
- 在 Ubuntu 里安装 Redis:
sudo apt update sudo apt install redis-server sudo service redis-server start redis-cli
2. Linux 安装
方法 A:APT(Debian/Ubuntu)
vbscript
sudo apt update
sudo apt install redis-server
sudo systemctl enable redis-server
sudo systemctl start redis-server
php
114 Bytes
© 菜鸟-创作你的创作
方法 B:YUM(CentOS/RHEL)
sql
sudo yum install epel-release
sudo yum install redis
sudo systemctl enable redis
sudo systemctl start redis
php
107 Bytes
© 菜鸟-创作你的创作
方法 C:源码编译(通用)
go
wget http://download.redis.io/releases/redis-7.2.4.tar.gz
tar -zxvf redis-7.2.4.tar.gz
cd redis-7.2.4
make
sudo make install
redis-server
php
137 Bytes
© 菜鸟-创作你的创作
3. macOS 安装
使用 Homebrew
sql
brew update
brew install redis
brew services start redis
redis-cli
php
66 Bytes
© 菜鸟-创作你的创作
四、启动与测试
启动 Redis
vbscript
redis-server
php
12 Bytes
© 菜鸟-创作你的创作
客户端连接
sql
redis-cli
set user "xiaoming"
get user
php
38 Bytes
© 菜鸟-创作你的创作
检查是否运行
bash
redis-cli ping
# 返回 PONG 表示正常
php
29 Bytes
© 菜鸟-创作你的创作
五、常用配置文件位置
- Linux :
/etc/redis/redis.conf
- macOS (brew) :
/usr/local/etc/redis.conf
- Windows 移植版 :
redis.windows.conf
建议常改的配置:
bash
bind 0.0.0.0 # 允许远程访问
requirepass 123456 # 设置密码
php
55 Bytes
© 菜鸟-创作你的创作
修改后重启:
sudo systemctl restart redis
php
28 Bytes
© 菜鸟-创作你的创作