尝试在地图(Jedis)中设置字符串时出现WRONGTYPE异常

时间:2018-06-26 11:57:11

标签: java string exception redis jedis

尝试将字符串设置为值时,我收到了JedisDataException异常,如果我只执行一个操作,则似乎无法弄清楚我在哪里出错。 Jedis版本是2.9.0(我相信它是最新版本)。

redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value
    at redis.clients.jedis.Protocol.processError(Protocol.java:127) ~[?:?]
    at redis.clients.jedis.Protocol.process(Protocol.java:161) ~[?:?]
    at redis.clients.jedis.Protocol.read(Protocol.java:215) ~[?:?]
    at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) ~[?:?]
    at redis.clients.jedis.Connection.getIntegerReply(Connection.java:265) ~[?:?]
    at redis.clients.jedis.Jedis.hset(Jedis.java:658) ~[?:?]
    at net.ferskfisk.lobby.database.mongodb.Mongo$3.run(Mongo.java:174) ~[?:?]
    at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftTask.run(CraftTask.java:71) ~[1.12.jar:git-Spigot-3d850ec-809c399]
    at org.bukkit.craftbukkit.v1_12_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:52) [1.12.jar:git-Spigot-3d850ec-809c399]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
    at java.lang.Thread.run(Unknown Source) [?:?]

                String name = "name";
                String string = "test";
                Jedis jedis = null;
                try {
                    jedis = Database.getInstance().getRedis().getJedisPool().getResource();
                    jedis.auth("password");
                    jedis.hset(name, "doc", string);
                } finally {
                    if(jedis != null)
                        jedis.close();
                }

1 个答案:

答案 0 :(得分:0)

在没有堆栈跟踪的情况下,最可能的解释是您已经有一个名为name的密钥,并且它不是哈希。