企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 组件源码 /** * <b>方法描述:</b> 重命名key <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-09 10:11:23 <br/> * * @param oldkey * 入参|修改的键|{@link java.lang.String} * @param newkey * 入参|新键名称|{@link java.lang.String} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "重命名key", style = "判断型", type = "同步组件", comment = "RENAMENX命令。仅在newkey不存在时有效,oldkey不存在时异常", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-09 10:11:23") @InParams(param = { @Param(name = "oldkey", comment = "修改的键", type = java.lang.String.class), @Param(name = "newkey", comment = "新键名称", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功") }) public static ResultBase P_renameKey(String oldkey, String newkey) { try { if (redisTemplate.renameIfAbsent(oldkey, newkey)) return ResultBase.newSuccessResult(); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTR3003", "重命名key 异常:" + AppLog.errorMsg(e)); } return ResultBase.newFailureResult("TPTR3004", "key rename失败"); } 交易中组件使用方式: ![](https://img.kancloud.cn/09/41/0941927136ec5b4aab8757cb968c04de_1140x1140.jpg) ## 参数说明及示例 修改的键:redis中已存在的key,示例: `"oldKey"` 新键名称:redis中未存在的key,示例: `"newKey"` > RENAMENX命令。仅在newkey不存在时有效,oldkey不存在时异常