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

3802 ワード

関連接続:Canalを通じてあるウェブサイトのRedisとMySqlのデータが自動的に同期することを保証する
1.エラーメッセージ
redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value

2.分析
現在のプログラム内のkeyの操作タイプは、redisライブラリに存在するkeyのタイプと一致しません.例:keyを最初に保存し、key-value形式に設定する
[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"

2回目にkeyを保存し、key-map形式で保存するとエラーが発生します
192.168.6.123:6379> hmset my_test_userid_001 user001 "0001" user002 "0002"
(error) WRONGTYPE Operation against a key holding the wrong kind of value

前のキーを削除すると、現在の操作は次のようにできます.
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.問題解決
3.1.一時的な解決
競合keyを削除するには、次のようにします.
192.168.6.123:6379> del my_test_userid_001

3.2.根本的に解決する.
この問題は、プログラムが同じkeyを複数で使用しているに違いない.また、key-valueタイプ、key-mapタイプ、key-objectタイプが異なる.プログラムを表示して、この競合を見つけて、変更します.