直接用increment自增多少初始化,不能用set,否则操作incr时会出现问题,报错类型不匹配
@PostConstruct
public void init() {
Long maxIdDb = paymentLogMapper.findMaxId();
if (maxIdDb == null) {
//incr会自己初始化并自增
return;
}
String key = Constants.PAYMENT_LOG_MAX_ID;
Long value = redisService.getCacheObject(key);
if (value == null) {
redisService.incrBy(key, maxIdDb);
} else if (maxIdDb - value != 0) {
redisService.incrBy(key, maxIdDb - value);
}
}
@Override
public PaymentLog createPaymentLog() {
Long maxId = redisService.incrBy(Constants.PAYMENT_LOG_MAX_ID, 1L);
PaymentLog paymentLog = new PaymentLog();
paymentLog.setId(IdUtils.genPaymentLogId());
return paymentLog;
}