1 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
- 其中这几个是redis所依赖的jar包
1 | <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils --> |
- Spring的配置文件
1 | <?xml version="1.0" encoding="UTF-8"?> |
- 该jar中就提供了两个对象:
- StringRedisTemplate: 对string的类型进行的存储的
- 我这里仅仅提供了简单的方法:
- 1.opsForValue().set(key, value)
- 2.a.opsForValue().get(key);
- ValueOperations:对于byte[]的数组的转换处理(配置序列化的工具)
- valueOperations.set(key, stuModel);
- valueOperations.get(key)
- StringRedisTemplate: 对string的类型进行的存储的
1 | public class RedisSpring { |
- 主函数进行读取配置文件获取 对象:
1 | package springdata; |
- redis主要在数据库和redis起到缓存的作用:当一个请求发出的时候,在数据层进行请求数据的时候,进行一个判断并且对redis进行判断,如果redis里面有,就直接进行取出,反馈,如果没有就继续访问数据库查出数据,这样就大大节省了效率,而且redis数据是存储在内存的,读写的速度也相对数据库更快。这就是redis的优势 ,也就是她独到的地方。