DB-redis-base

redis springboot常用命令

1
2
3
4
5
6
7
8
9
10
11
@Autowired
StringRedisTemplate redisTemplate;
//----------------------------------------------------------------------
//给key设置value
redisTemplate.opsForValue().set("key","value"); //SET key "value"
//取key的value
redisTemplate.opsForValue().get("key");//GET key
//设置key在new Date()过期
redisTemplate.expireAt("key",new Date()); //EXPIREAT key timestamp
redisTemplate.getExpire("testttl"); //返回过期时间

注意

reids重新设值会覆盖expireAt过期时间的设置