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

created at 07-24-2021 views: 426

When using the following command when using redis, redis prompts an error: 

127.0.0.1:6379> rpush aaa item
WRONGTYPE Operation against a key holding the wrong kind of value

reason

It is because the key aaa is already in the redis, and the value type corresponding to this key is not a list collection, but a string, so the error is eliminated when using rpush.

Solution

1. Delete the key aaa before. Rewrite

2. Use a key that does not exist in redis.

Recommendations

If you are not sure what type of key is before using it, you can use the type method to determine the key type first, and then decide to call the method.

127.0.0.1:6379> type aaa 
>>> list
created at:07-24-2021
edited at: 07-24-2021: