如何构建一个springBoot项目就不再赘述
https://mp.youkuaiyun.com/postedit/88866362
只说说如何在已有的项目中添加 Redis中间件缓存。
首先添加pom.xml 中的依赖;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.13</version>
</dependency>
添加application.properties 中添加配置项
# REDIS (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=1
# Redis服务器地址
spring.redis.host=192.168.31.102
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=123456
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-idle=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=
# 连接池中的最大空闲连接
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout= 5000
redis 可以用自己的,用户名改为localhost 密码默认为 空 ;
编写一个测试方法:
测试基础的 get() set ()。
PS: StringRedisTemplate 是内置的不需要你来编写。
以上就是一个基础的 Redis 配置说明。