2021-06-02

springboot2.5.0 整合 redis 配置详解

1. pom添加依赖

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

2. application.properties 配置文件

#===========Redis配置===========# Redis数据库索引(默认为0) spring.redis.database=0# Redis服务器地址 spring.redis.host=127.0.0.1# Redis服务器连接端口 spring.redis.port=6379# Redis服务器连接密码spring.redis.password=root# 连接池最大连接数(使用负值表示没有限制) spring.redis.pool.max-active=200# 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=-1# 连接池中的最大空闲连接 spring.redis.pool.max-idle=10# 连接池中的最小空闲连接 spring.redis.pool.min-idle=0# 连接超时时间(毫秒)spring.redis.timeout=2000msspring.redis.jedis.pool.max-wait=-1ms#===========Redis配置===========

3. RedisConfig.java 配置类


4. 调用redis

 @Autowired private RedisTemplate<String, Object> redisTemplate;	/**	 * 普通缓存获取	 * @param key 键	 * @return 值	 */	public Object get(String key) {		return key == null ? null : redisTemplate.opsForValue().get(key);	}	/**	 * 普通缓存放入	 * @param key 键	 * @param value 值	 * @return true成功 false失败	 */	public boolean set(String key, Object value) {		try {			redisTemplate.opsForValue().set(key, value);			return true;		} catch (Exception e) {			//e.printStackTrace();			return false;		}	}









原文转载:http://www.shaoqun.com/a/777114.html

跨境电商:https://www.ikjzd.com/

aicpa:https://www.ikjzd.com/w/1373

米兰网:https://www.ikjzd.com/w/1304.html


1.pom添加依赖<!--redis--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency>2.application.
口述:老公喜欢看A片 不愿看我:http://lady.shaoqun.com/m/a/272284.html
女友找到有钱男后就甩了我:http://www.30bags.com/a/250914.html
女网友不甘寂寞找上我 口述我和漂亮女网友的那些事:http://www.30bags.com/m/a/250599.html
关注:强奸和通奸有什么区别?:http://lady.shaoqun.com/a/347954.html
以宠物用品类目做案例,教你如何避免"杀猪盘":https://www.ikjzd.com/articles/145289
跨境小白收藏|亚马逊专业术语学习分享:https://www.ikjzd.com/articles/145274
易联通:https://www.ikjzd.com/w/1854.html
识货:https://www.ikjzd.com/w/1745
美菜:https://www.ikjzd.com/w/1874

No comments:

Post a Comment