Redis:wrongtype Operation against a key holding the wrong kind of Value_redis

Source: Internet
Author: User

Related connections: Through the canal to ensure the redis of a website and MySQL data automatically synchronized 1. Error message

Redis.clients.jedis.exceptions.JedisDataException:WRONGTYPE Operation against a key holding the wrong kind of value
2. Analysis

The operation type of key in the current program does not match the type of key that exists in the Redis library. Example
Save key for the first time, set it to Key-value form

[Root@server3 src]#./redis-cli-h 192.168.6.123-p 6379-a ' {password} '
192.168.6.123:6379> set my_test_userid_ 001 "0001"
OK
192.168.6.123:6379> get my_test_userid_001
"0001"

Save the key for the second time, save it as Key-map, and you will get an error

192.168.6.123:6379> hmset my_test_userid_001 user001 "0001" user002 "0002"
(Error) Wrongtype Operation a K EY holding the wrong kind of value

If you delete the previous key, the current operation can take place:

192.168.6.123:6379> del my_test_userid_001
(integer) 1
192.168.6.123:6379> Hmset my_test_userid_001 user001 "0001" user002 "0002"
OK
192.168.6.123:6379> hgetall my_test_userid_001
1) "user001"
2) " 0001 "
3" user002 "
4" "0002"
192.168.6.123:6379> hmget my_test_userid_001 user001
1) "0001"
192.168.6.123:6379> del my_test_userid_001
(integer) 1
3. Problem solving 3.1. Temporary solution

Delete conflict key, similar to:

192.168.6.123:6379> del my_test_userid_001
3.2. A fundamental solution

Cause this problem, must be the program in many places use the same key, and is different type, some to Key-value type, some to Key-map, some to Key-object.
View the program, find the conflict, and modify it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.