👩🏽💻个人主页:阿木木AEcru
🔥 系列专栏:《Docker容器化部署系列》 《Java每日面筋》
💹每一次技术突破,都是对自我能力的挑战和超越。
↓↓↓↓↓↓精彩回顾↓↓↓↓↓↓↓
Redis高频面试题50道(一) - 掘金 (juejin.cn)
Redis高频面试题50道(二) - 掘金 (juejin.cn)
Docker部署Minio分布式存储+SpringBoot整合Minio - 掘金 (juejin.cn)
建议点赞收藏,方便后续使用!非常感谢大家的支持!!
一、部署Redis 7.2.4 (最新版本) 1.1 下载安装包
arduino
sudo wget https://download.redis.io/releases/redis-7.2.4.tar.gz
我这里在 /usr/local/redis 目录下执行的下载,可根据自己想要安装的目录自行选择。

1.2 解压安装包
sudo tar -zvxf redis-7.2.4.tar.gz

1.3 检测并安装 编译 C、C++ 以及其他编程语言的编译器 GCC
yum -y install gcc
我这里之前已经安装过了

1.4 编译安装
bash
cd redis-7.2.4 # 进到解压出来的文件夹
sudo make #执行编译

等待编译完成后进行安装
go
sudo make install

1.5 开启远程访问
sudo vim redis.conf

1.6 启动Redis
vbscript
redis-server redis.conf &

bash
ps -df | grep redis
可以查看一下redis进程是否启动

1.7 进入设置密码
csharp
#进入客户端
redis-cli
#修改密码
config set requirepass <你的密码>
#认证密码
auth <你的密码>
#查看密码
config get requirepass

1.8 开启防火墙端口
css
sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
sudo firewall-cmd --reload
注:如果是使用云服务器,还需要开启安全组入口端口。
1.9 测试连接redis


这样即为连接成功
二、SpringBoot整合Reids
2.1 引入依赖
xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>
2.2 配置yml文件
yaml
spring:
redis:
#ip地址
host: 10.xx.xxx.21
#端口号
port: 6379
#密码
password: axxxxxxxxxxxxUW
2.3 编写单元测试类
less
@Slf4j
@SpringBootTest
public class RedisTest {
@Autowired
private StringRedisTemplate redisTemplate;
@Test
void test01() {
ValueOperations<String, String> opsForValue = redisTemplate.opsForValue();
//查询key
String value1 = opsForValue.get("test-key");
System.out.println("写入前值为:"+value1);
opsForValue.set("test-key","123456");
String value2 = opsForValue.get("test-key");
System.out.println("写入后值为:"+value2);
}
}
2.4 测试结果



感谢观看至此,希望该文章能够帮助到您提升知识和技能。如果您喜欢我的内容,请不要忘记点赞和分享哦!👍
