Redis - WRONGTYPE Operation against a key holding the wrong kind of value

2023-11-17

用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);
}

添加了一个字符串跟物料编码连接,就不再报错了

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Redis - WRONGTYPE Operation against a key holding the wrong kind of value 的相关文章

随机推荐