连接Redis服务器时出现java.lang.NoSuchFieldError: WRITE_BUFFER_HIGH_WATER_MARK异常。我已在代码中删除了实际的主机和端口详细信息。

Exception in thread "main" java.lang.NoSuchFieldError: WRITE_BUFFER_HIGH_WATER_MARK
    at io.lettuce.core.AbstractRedisClient.connectionBuilder(AbstractRedisClient.java:148)
    at io.lettuce.core.RedisClient.connectStatefulAsync(RedisClient.java:303)
    at io.lettuce.core.RedisClient.connectStandaloneAsync(RedisClient.java:271)
    at io.lettuce.core.RedisClient.connect(RedisClient.java:204)
    at io.lettuce.core.RedisClient.connect(RedisClient.java:189)
    at testpack.RedisClientTest.setCacheIntoRedis(RedisClientTest.java:30)
    at testpack.RedisClientTest.main(RedisClientTest.java:24)


代码:

public class RedisClientTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        setCacheIntoRedis("TestKey", "Hello Redis");

    }

    public static void setCacheIntoRedis(String key, String value) {
        // Removed actual server details
        RedisClient redisClient = RedisClient.create("redis://redis123@host:port/0");
        StatefulRedisConnection<String, String> connection = redisClient.connect();
        RedisCommands<String, String> syncCommands = connection.sync();

        syncCommands.set(key, value);

        connection.close();
        redisClient.shutdown();
    }

}

最佳答案

由于存在不同版本的Netty依赖项,因此您有冲突。生菜5.1.7实际上取决于netty 4.1.36,因为您应该使用netty-all 4.1.36而不是4.0.0。

08-29 00:56