[英]Redis transaction does now throw error even after failing in Spring boot
我正在使用 spring boot 并在其中实现了 Redis 事务。
public void storeSession(Session session) {
try {
log.info("Inside storeSession");
cacheClient.watch(tokenUtility.getToken());
Session savedSession = getSession();
if (savedSession.getVersion() == session.getVersion()) {
session.setVersion(session.getVersion() + 1);
sessionManager.storeSessionData(session);
} else {
log.error("Saved Session Version is different than current session");
throw new OptimisticLockException(OPTIMISTIC_LOCK_ERROR);
}
} catch (JsonProcessingException e) {
log.error("Error occured while converting json to string, message-key {}", TuplesKt.to("message-key", JSON_PROCESSING_ERROR));
throw new PrepaidRegistrationBffRuntimeException(JSON_PROCESSING_ERROR, e);
}
}
@Transactional
public void storeSessionData(Session session) throws JsonProcessingException {
cacheClient.save(tokenUtility.getToken(), mapper.writeValueAsString(session), prepaidPropertiesConfig.getRedisKeyExpiryInMillis(), TimeUnit.MILLISECONDS);
log.info("Session Stored seccessfully for, tokenhash : {}", to("tokenhash", tokenUtility.getToken()));
}
根据上面提到的代码,我首先观察我正在更新的密钥,在执行事务之间,我在 redis 中手动更新了该密钥。 在这种情况下,事务失败但不会抛出任何异常。 我不确定如何确保我的交易成功?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.