Five data structure operations are defined in RedisTemplate
redisTemplate.opsForValue();//操作字符串
redisTemplate.opsForHash();//操作hash
redisTemplate.opsForList();//操作list
redisTemplate.opsForSet();//操作set
redisTemplate.opsForZSet();//操作有序set
RedisTemplate's operations on these five data structures are similar, the following takes the operation string as an example:
1. Add Redis dependency
<!-- redis依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
2. Inject RedisTemplate first
@Autowired
private RedisTemplate<String,String> redis;
3. Set the key and value values: the first parameter represents Key, and the second parameter represents Value
redis.opsForValue().set("Token", "Kzl6N3RJeFBmQlNQamlVNW4zUThoQT09");//设置值
4. Set the timeout period. The first parameter indicates the Key name, the second parameter indicates the time, and the third parameter indicates milliseconds, minutes, days, etc.
redis.expire("Token",3,TimeUnit.MINUTES);//设置过期时间3分钟
5. Get the key value: the parameter represents the key name
redis.opsForValue().get("Token");
The picture below is the data stored in redis