企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 /** * <b>方法描述:</b> 设置值(不覆盖) <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-09 10:56:04 <br/> * * @param key * 入参|key|{@link java.lang.String} * @param value * 入参|value|{@link java.lang.String} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "设置值(不覆盖)", style = "判断型", type = "同步组件", comment = "只有key不存在才会设置", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-09 10:56:04") @InParams(param = { @Param(name = "key", comment = "key", type = java.lang.String.class), @Param(name = "value", comment = "value", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功") }) public static ResultBase P_setNx(String key, String value) { try { if (redisTemplate.opsForValue().setIfAbsent(key, value)) return ResultBase.newSuccessResult(); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTR5008", "设置值(不覆盖) 异常:" + AppLog.errorMsg(e)); } return ResultBase.newFailureResult("TPTR5007", "设置值(不覆盖)失败"); } 交易中组件使用方式: ![](https://img.kancloud.cn/eb/5e/eb5ee2ecb6338c4feb35e1d810b92edb_950x750.jpg) ## 参数说明及示例 key:redis中的key,示例: `"qwer"` value:设置的值,示例: `"newvalue"` > 只有key不存在才会设置,可以理解为创建一个新的redis值