一、系统版本
- Linux:CentOS Linux release 7.6.1810 (Core)
- Redis:3.2.12
二、安装Redis
// 1.使用yum安装redis
[root@localhost ~]# yum -y install redis
// 2.启动redis
[root@localhost ~]# systemctl start redis
// 3.查看redis状态(如果Active为active(running)表示安装成功)
[root@localhost ~]# systemctl status redis
三、测试Redis
// 4.进入redis
[root@localhost ~]# redis-cli
127.0.0.1:6379> set 'test' 'hello'
OK
127.0.0.1:6379> get 'test'
"hello"
四、配置Redis
1、搜索配置文件
[root@localhost ~]# whereis redis.config
redis: /etc/redis.conf
2、编辑配置文件
#允许远程访问
#bind 127.0.0.1
#端口号
port 6379
#设置密码
requirepass 666666
#关闭保护
protected-mode no
3、重启Redis服务
[root@localhost ~]# systemctl restart redis
五、远程连接Redis
使用 PowerShell / CMD 连接
// 这里的127.0.0.1请改为自己服务器的ip地址,6379改为自己的端口
C:\WINDOWS\system32> redis-cli -h 127.0.0.1 -p 6379
// 这里直接获取key值结果报错,需要先登录一下
127.0.0.1:6379> get 'test'
(error) NOAUTH Authentication required.
// 登录Redis
127.0.0.1:6379> auth 666666
OK
// 再次获取key值,发现已经能获取了,就是上面设置的
127.0.0.1:6379> get 'test'
"hello"
使用 Redis Desktop Manager 连