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

问题描述 投票:0回答:2

当我尝试将字符串设置为值时,我收到了 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();
                }
java string exception redis jedis
2个回答
0
投票

在没有堆栈跟踪的情况下,最可能的解释是您已经有一个名为

name
的键,但它不是哈希值。


0
投票

使用

new String("your string value")
保存

© www.soinside.com 2019 - 2024. All rights reserved.