Redis说明
redis是一个key-value库,在java中的使用,作为小型数据的缓存比较常见。
比如,管理员实现角色分配权限时,每次操作时都会执行很多查询,这样会影响效率。怎么提升程序性能呢?我们可以考虑用缓存数据库来实现。
代码下载地址
https://github.com/weiaiwan/redisdemo
创建项目
创建springboot项目时勾选
勾选后项目会自动导入jar
使用redis缓存有三步
1、配置application.properties中的redis
#springboot+mybatis
# 加载mybatis配置
mybatis.config-location=classpath:mapper/config/mybatis-config.xml
mybatis.mapper-locations=classpath:mapper/*.xml
# 数据源
spring.datasource.url=jdbc:mysql://120.199.82.51:3062/px_user?useUnicode=true&characterEncoding=UTF-8
#数据源驱动
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
#redis
spring.redis.host=127.0.0.1
spring.redis.port=6379
2、在启动项目类上加@EnableCaching
package com.example.redisdemo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot