springboot2 redis
2021-07-11 03:06
标签:image context 代码 prope 超时 缓存 value efault show 本项目使用jar包: springboot2 redis 标签:image context 代码 prope 超时 缓存 value efault show 原文地址:https://www.cnblogs.com/cnJun/p/9552411.html parent>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-parentartifactId>
version>2.0.4.RELEASEversion>
relativePath/>
parent>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-data-redisartifactId>
dependency>
#redis
spring.redis.host=127.0.0.1
spring.redis.port=6379
# 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
spring.redis.timeout=60s
# 连接池配置,2.0中直接使用jedis或者lettuce配置连接池
# 最大活跃连接数,负数为不限制
spring.redis.lettuce.pool.max-active=500
# 等待可用连接的最大时间,负数为不限制
spring.redis.lettuce.pool.max-wait=-1ms
# 最大空闲连接数
spring.redis.lettuce.pool.max-idle=100
# 最小空闲连接数
spring.redis.lettuce.pool.min-idle=20
package com.chenyingjun.springboot2.config;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* RedisConfig工具类配置
*
* @author chenyingjun
* @since 1.0
* @version 2018年8月15日 chenyingjun
*/
@Configuration
@EnableCaching
public class RedisConfig {
/**
* RedisTemplate配置
*/
@Bean
public RedisTemplate
@Cacheable(key="‘userId_‘+#id", value="user")
public SystemUserVo info(String id) {
System.out.println("-------------------------------------------------------");
SystemUserVo user = systemUserMapper.info(id);
return user;
}
上一篇:Python 编码规范
下一篇:Python环境搭建
文章标题:springboot2 redis
文章链接:http://soscw.com/index.php/essay/103521.html