Docker 安装 Redis + Spring Boot 整合 Redis

Docker安装Redis

一、启动docker容器

systemctl start docker

二、拉取redis镜像

docker pull redis

三、端口映射

docker run --name redis -p 6379:6379 -d redis

四、启动redis

docker start redis

五、查询ip

ip addr

六、连接redis


Spring boot 整合 redis

一、添加依赖

	<dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>

二、配置yml文件

server:
  port: 8080

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/studentdb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
    username: root
    password: root

  redis:
    host: #此处应填写服务器ip 通过上述命令 ip addr 可查看
    #redis端口
    port: 6379
    # Redis数据库索引(默认为0) 密码之类的 默认是没有的可以写
    database: 0

# 打印SQL语句
logging:
  level:
  	#改为自己的mapper包路径
    com.nebula.springboot_redis.mapper: debug

三、启动类中加入注解

@MapperScan(value = "com.nebula.springboot_redis.mapper") //指定要扫描的mapper包路径

@SpringBootApplication
public class SpringbootRedisApplication {
   

    public static void main(String[] args) {
   
        SpringApplication.run(SpringbootRedisApplication.class, args);
    }

}

项目结构如下:

四、加入RedisConfig文件

@Configuration
public class RedisConfig {
   
    @Bean
    @SuppressWarnings("all")
    public RedisTemplate
  • 6
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值