SpringBoot项目集成Redis

本文介绍了如何在SpringBoot项目中集成Redis,包括在pom.xml添加相关依赖,配置application.yml文件,创建RedisConfig配置,以及展示了User和DemoController的使用示例。
摘要由CSDN通过智能技术生成

一、在pom文件中添加依赖

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

二、在application.yml文件中配置redis

spring:
  redis:
    host: 127.0.0.1 #redis服务器IP地址
    port: 6379 #端口号
    jedis:
      pool:
        max-active: 8 #最大连接数
        max-idle: 8 #最大空闲数
        min-idle: 0 #最小空闲数
        max-wait: 30000 #最大等待时间 ms(毫秒)
    timeout: 50000 #连接超时时间 ms(毫秒)
    database: 0 #连接的数据库

三、创建RedisConfig文件

package com.xf.base.config;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值