springboot 集成redis (单点)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27603235/article/details/78847135

最近做一些关于springboot方面的东西,刚好抽空准备集成一下关于redis的部分,但是看 了网上的很多教程,不过都不是很对。现在完整的教程下一下,以备以后查阅使用。
springboot是属于开箱即用的那种,对于redis的使用也是一样。下面开始讲怎么使用springboot集成redis。
项目是采用maven构建,以下是需要的jar包。

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
        <version>1.5.6.RELEASE</version>
</dependency>

然后在application.properties 中配置关于redis的项。

spring.redis.database=0
spring.redis.host=192.168.29.128
spring.redis.password=
spring.redis.port=6379
spring.redis.pool.max-idle=8
spring.redis.pool.min-idle=0  
spring.redis.pool.max-active=8  
spring.redis.pool.max-wait=-1

只需要这样就可以完成springboot+redis的基本配置,在项目中可以通过注解的方式,将redisTemplate和stringRedisTemplate注入到MVC层中。通过提供的方法来完成对redis 的一些基本操作。

猜你喜欢

转载自blog.csdn.net/qq_27603235/article/details/78847135