ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 组件源码 /** * <b>方法描述:</b> 赋值并返回旧值 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-09 10:57:07 <br/> * * @param key * 入参|key|{@link java.lang.String} * @param value * 入参|value|{@link java.lang.String} * @param oldvalue * 出参|旧值|{@link java.lang.String} * @return -1 异常<br/> * 1 成功<br/> */ @Component(label = "赋值并返回旧值", style = "判断型", type = "同步组件", comment = "自动将key对应到value并且返回原来key对应的value。如果key存在但是对应的value不是字符串,就返回错误", version = "1.0.0", deprecated = false, author = "admin", date = "2018-05-09 10:57:07") @InParams(param = { @Param(name = "key", comment = "key", type = java.lang.String.class), @Param(name = "value", comment = "value", type = java.lang.String.class) }) @OutParams(param = { @Param(name = "oldvalue", comment = "旧值", type = java.lang.String.class) }) @Returns(returns = { @Return(id = "-1", desp = "异常"), @Return(id = "1", desp = "成功") }) public static ResultBase P_getset(String key, String value) { Object obj = null; try { obj = redisTemplate.opsForValue().getAndSet(key, value); return ResultBase.newSuccessResult(obj.toString()); } catch (Exception e) { AppLog.error(e); return ResultBase.newExceptionResult("TPTR5012", "赋值并返回旧值 异常:" + AppLog.errorMsg(e)); } } 交易中组件使用方式: ![](https://img.kancloud.cn/f0/52/f052bbab5ab1743fdfd72458ac9199e7_950x750.jpg) ## 参数说明及示例 key:redis中的key,示例: `"qwer"` value:新设置的值,示例: `"newvalue"` 旧值:返回旧值,示例: `__INNER__["oldvalue"]` > 自动将key对应到value并且返回原来key对应的value。如果key存在但是对应的value不是字符串,就返回错误