add 增加 RedisUtils 测试设置过期时间 案例

feature/model
疯狂的狮子li 3 years ago
parent d0700172fa
commit 255c8a083e

@ -1,6 +1,7 @@
package com.ruoyi.demo.controller;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@ -12,6 +13,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.TimeUnit;
/**
* spring-cache
*
@ -76,4 +79,24 @@ public class RedisCacheController {
return AjaxResult.success("操作成功", value);
}
/**
*
* 10
* 11
*/
@ApiOperation("测试设置过期时间")
@GetMapping("/test6")
public AjaxResult<Boolean> test6(String key, String value){
RedisUtils.setCacheObject(key, value);
boolean flag = RedisUtils.expire(key, 10, TimeUnit.SECONDS);
System.out.println("***********" + flag);
try {
Thread.sleep(11 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Object obj = RedisUtils.getCacheObject(key);
return AjaxResult.success("操作成功", value.equals(obj));
}
}

Loading…
Cancel
Save