天天看點

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

  • 報錯

127.0.0.1:6379>ZADD runoobkey 1 redis

(error) WRONGTYPE Operation against a key holding the wrong kind of value

  • 前面

    大家學習redis 肯定先是學習j集合set 再學習有序集合sorted set 肯定會遇到這個問題 >.<

  • 原因

    runoobkey 存在的是key-set格式,不能ZADD操作, 操作不比對

EXISTS runoobkey

(integer) 1

一個相同的例子

127.0.0.1:6379>SET name xiaoming

OK

127.0.0.1:6379>ZADD name 1 xiaoming

(error) WRONGTYPE Operation against a key holding the wrong kind of value

因為name已經被設定過key-value形式,不能重新設定為

  • 解決

    更換其他名(key),或者删除以前的key

127.0.0.1:6379>ZADD runoobkey 1 redis

(integer) 1

127.0.0.1:6379>del runoobkey

(integer) 1

127.0.0.1:6379>ZADD runoobkey 1 redis

(integer) 1