springboot 集成redis (单点)

来源:互联网 发布:线切割编程3b 编辑:程序博客网 时间:2024/06/15 05:40

最近做一些关于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=0spring.redis.host=192.168.29.128spring.redis.password=spring.redis.port=6379spring.redis.pool.max-idle=8spring.redis.pool.min-idle=0  spring.redis.pool.max-active=8  spring.redis.pool.max-wait=-1

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

原创粉丝点击