redis是基于内存的key-value系统,能够用做缓存中间件或者消息中间件,spring-boot提供了方便的方式和redis集成。java
<!--redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
spring: application: name: monocase-framework # 应用名称 jackson: date-format: yyyy-MM-dd HH:mm:ss # 日期格式 datasource: druid: # 链接池别名 url: jdbc:mysql://${MYSQL_HOST:192.168.1.200}:${MYSQL_PORT:3306}/zhya-monocase-framework?useUnicode=true&characterEncoding=utf8 username: root password: root@123 type: com.alibaba.druid.pool.DruidDataSource # 链接池类型 driver-class-name: com.mysql.jdbc.Driver poolPreparedStatements: true maxOpenPreparedStatements: 100 maxActive: 100 maxWaitMillis: 5000 redis: database: 1 host: ${REDIS_HOST:192.168.1.200} port: ${REDIS_PORT:6379} jedis: pool: max-active: 100 max-wait: 2000ms
第一次会进行数据库查询mysql
第二次则不会,由于redis中已经缓存了redis