redis出现WRONGTYPE Operation against a key holding the wrong kind of value错误

操做redis时,想设置一个hash值,出现了WRONGTYPE Operation against a key holding the wrong kind of value 的错误

HashOperations hashOperations = redisTemplate.opsForHash();

hashOperations.put("user", "name", "zhangsan");

出现

Caused by: io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value

出现此状况的缘由颇有多是由于:

redis中已经存在同名,但不一样类型的key值。

因而用type命令查看了此键值的类型,结果显示是字符串,所以用hash的命令,没法执行。

确保此键值没用后,用del命令删除或者更改key名称即可。

HashOperations hashOperations = redisTemplate.opsForHash();

hashOperations.put("new_name", "name", "zhangsan");

你可能感兴趣的:(redis,kind,缓存)