通过redis获取当日流水号出现初始值不为1的情况

java通过redis自增获取当日的流水号,键值为工厂加年月日,字段过期时间为一天
实现每个工厂每天单独一个流水号,起始值都为零
但是有时候这个流水号会莫名的变化,之前有过突然跳过好几位的情况,今天就是初始值不为1
代码如下

public static synchronized String getCodeId(String factoryCode,RedisTemplate<String,String> redisTemplate){

        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DATE);
        int month = calendar.get(Calendar.MONTH)+1;
        int year = calendar.get(Calendar.YEAR);
        String key =factoryCode+year+month+day;
        String code = redisTemplate.boundValueOps(key).get();
        if (StringUtils.isEmpty(code)){
            code = "1";
            redisTemplate.boundValueOps(key).set(code,1, TimeUnit.DAYS);
        }
        redisTemplate.boundValueOps(key).increment(1);
        return code;
    }

检查了好几遍都没想出来哪里有问题,方法也是上了锁的,不存在共用一个code情况

看看调用方,有可能调用方回滚了,导致数据添加到数据库失败,但是redis的流水号自增了