用RedisTemplate把数据存入Redis,key值为物料编码,value值为对应对象,但相同物料编码对应的对象不一定唯一故采用Set。
for (int i = 0; i < retrospectiveBomSbomtList.size(); i++) {
Sbom sbom1 = retrospectiveBomSbomtList.get(i);
redisTemplate.opsForSet().add(sbom1.getItemNumber(), sbom1);
}
在存入数据的过程中报错:WRONGTYPE Operation against a key holding the wrong kind of value。
经过多次测试,发现是key值物料编码造成错误发生,因为物料编码是String类型的数字,例如:36033020003。
故修改为:
for (int i = 0; i < retrospectiveBomSbomtList.size(); i++) {
Sbom sbom1 = retrospectiveBomSbomtList.get(i);
redisTemplate.opsForSet().add("mes" + sbom1.getItemNumber(), sbom1);
}
添加了一个字符串跟物料编码连接,就不再报错了