轻松部署Redis 7.2.4 + SpringBoot整合Redis使用(一套保姆级教程)

👩🏽‍💻个人主页:阿木木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 测试结果

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

相关推荐
考虑考虑1 天前
Jpa使用union all
java·spring boot·后端
RestCloud1 天前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud1 天前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence1 天前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
阿杆1 天前
同事嫌参数校验太丑,我直接掏出了更优雅的 SpEL Validator
java·spring boot·后端
DemonAvenger1 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
AAA修煤气灶刘哥2 天前
别让Redis「歪脖子」!一次搞定数据倾斜与请求倾斜的捉妖记
redis·分布式·后端
AAA修煤气灶刘哥2 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
昵称为空C2 天前
SpringBoot3 http接口调用新方式RestClient + @HttpExchange像使用Feign一样调用
spring boot·后端
RestCloud2 天前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api