订单支付倒计时redis实现
@GetMapping("/addOrder")
public String addOrder() {
//创建订单...数据库操作
//订单ID存到Redis,存30分钟
redisTemplate.opsForValue().set("orderId1234", "添加的订单", 30, TimeUnit.MINUTES);
return "success";
}
/**30分钟内查询key是否存在*/
@GetMapping("/queryOrder")
public String queryOrder(@RequestParam String orderId) {
//查询订单ID是否存在
Boolean hasKey = redisTemplate.hasKey(orderId);
//查询订单id的剩余时间
Long expire = redisTemplate.getExpire(orderId);
System.out.println(expire);
if (hasKey) {
return "订单存在"+expire;
}
return "订单不存在";
}
标签:orderId,String,redis,倒计时,订单,hasKey,redisTemplate
From: https://www.cnblogs.com/pushbug/p/18363072