Springboot整合Redis,高并发下访问缓存与写入缓存

1、配置Redis连接:添加pox.xml依赖:


		
			org.springframework.boot
			spring-boot-starter-data-redis
		
		
		
			org.apache.commons
			commons-pool2
		

2,application.yml

server:
  port: 8989
spring:
  datasource:
    username: root
    password: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    #连接本地数据库
    url: jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC

  redis:
    host: 127.0.0.1
    timeout: 1000
    jedis:
      pool:
        min-idle: 5
        max-idle: 10
        max-wait: -1

mybatis-plus:
  # mapper.xml 文件扫描
  mapper-locations: classpath*:/mapper/*.xml
  configuration:
    map-underscore-to-camel-case: true

# 日志配置
logging:
  level:
    com.xxx.xxx: debug
    org.springframework: warn

对Redis生成的key,value进行数据格式转换一下:工具类 RedisConfig

/**
 * 设定redis返回的展示格式
 */
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory){
        RedisTemplate redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(factory);

        //指定key,value的序列化方式
        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        return redisTemplate;
    }
}

 

3,生成MVC基础结构:《简单利用mybatis-plus代码生成》

mybatis-plus代码生成器实现规则《超详细》_@小杨爱偷懒的博客-CSDN博客一.在pox添加所需的依赖: com.baomidoumybatis-plus-boot-starter3.3.1

你可能感兴趣的:(Redis并发,redis,缓存,spring,boot)