ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 /** * <b>方法描述:</b> 设置过期时间(毫秒) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-09 10:33:54 <br/> * * @param key * 入参|key|{@link java.lang.String} * @param milliseconds * 入参|毫秒|{@link long} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "设置过期时间(毫秒)", style = "判断型", type = "同步组件", comment = "时间按照当前时间计算,redis将会从缓存中删除掉该key;重复设置将会覆盖原先设置,", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-09 10:33:54") @InParams(param = { @Param(name = "key", comment = "key", type = java.lang.String.class), @Param(name = "milliseconds", comment = "毫秒", type = long.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_pexpire(String key, long milliseconds) { try { if (redisTemplate.expire(key, milliseconds, TimeUnit.MILLISECONDS)) return ResultBase.newSuccessResult(); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTR3010", "设置过期时间(毫秒) 异常:" + AppLog.errorMsg(e)); } return ResultBase.newFailureResult("TPTR3011", "设置过期时间失败"); } 交易中组件使用方式: ![](https://img.kancloud.cn/d8/f7/d8f7fd4dd7c75ab7a11a9596ef521c05_950x750.jpg) ## 参数说明及示例 key:redis中存在的key,示例: `"key"` 毫秒:redis中存在的key设置的过期时间,单位为毫秒,示例: `1000000` > 时间按照当前时间计算,redis将会从缓存中删除掉该key;重复设置将会覆盖原先设置