redisson classNotFoundException异常

发布于 2025-01-19 05:07:06 字数 1088 浏览 0 评论 0原文

我正在尝试使用RSET存储我的排名,但是在班级存在的同类时我有一个ClassNotFoundException(我什至分解了,课程在这里)。我认为Redisson无法存储自定义对象类? 这是我的代码:

public class RedisProvider {

    private final RSet<Rank> ranks;
    private final RedissonClient client;


    public RedisProvider() {
        this.client = Redisson.create();
        this.ranks = client.getSet("ranks");
        Rank rank = new Rank("default", 0, "&7", "&7");
        addRank(rank);
    }

    public Set<Rank> getRanks(){
        return ranks.readAll();
    }


    public void addRank(Rank rank) {
        ranks.add(rank);
    }

}

错误:

[17:51:39 ERROR]: Unable to decode data. channel: [id: 0xb12f3447,
L:/127.0.0.1:58768 - R:127.0.0.1/127.0.0.1:6379], reply:
ReplayingDecoderByteBuf(ridx=146, widx=146), command: (SSCAN), promise:
java.util.concurrent.CompletableFuture@4e7fd89e[Not completed, 1
dependents], params: [ranks, 0, COUNT, 10] java.io.IOException:
java.lang.ClassNotFoundException: fr.rhodless.test.Rank

我检查了“等级”类是否存在并且存在。

I'm trying to use a RSet to store my ranks, but I have a ClassNotFoundException while the class exists (I even decompiled and the class is here). In my opinion Redisson cannot store a custom object class?
Here is my code:

public class RedisProvider {

    private final RSet<Rank> ranks;
    private final RedissonClient client;


    public RedisProvider() {
        this.client = Redisson.create();
        this.ranks = client.getSet("ranks");
        Rank rank = new Rank("default", 0, "&7", "&7");
        addRank(rank);
    }

    public Set<Rank> getRanks(){
        return ranks.readAll();
    }


    public void addRank(Rank rank) {
        ranks.add(rank);
    }

}

Error:

[17:51:39 ERROR]: Unable to decode data. channel: [id: 0xb12f3447,
L:/127.0.0.1:58768 - R:127.0.0.1/127.0.0.1:6379], reply:
ReplayingDecoderByteBuf(ridx=146, widx=146), command: (SSCAN), promise:
java.util.concurrent.CompletableFuture@4e7fd89e[Not completed, 1
dependents], params: [ranks, 0, COUNT, 10] java.io.IOException:
java.lang.ClassNotFoundException: fr.rhodless.test.Rank

I checked if the "Rank" class existed and it exists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2025-01-26 05:07:06

您可以以“ bytearraycodec”/“ jsonjacksoncodec”的形式编写自己的“ org.redisson.client.codec.codec”的实现。
例如,我根据我们的需求写了一封。

import org.redisson.client.codec.BaseCodec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;

import io.netty.buffer.Unpooled;

/**
 * Encoder/Decoder for {@code Codec}.
 */
final class SnappyCodec extends BaseCodec {

    static final SnappyCodec INSTANCE = new SnappyCodec();

    private static final Encoder ENCODER = in -> Unpooled.wrappedBuffer(SnappyCompressor.getInstance().serializeAndCompress(in));

    private static final Decoder<Object> DECODER = (buf, state) -> {
        final byte[] result = new byte[buf.readableBytes()];
        buf.readBytes(result);
        return SnappyCompressor.getInstance().uncompressAndDeserializeWithFallbackToDeserializedDataBuffer(result);
    };

    @Override
    public Decoder<Object> getValueDecoder() {
        return DECODER;
    }

    @Override
    public Encoder getValueEncoder() {
        return ENCODER;
    }
}

You can write your own implementation of "org.redisson.client.codec.Codec" in the form of "ByteArrayCodec"/ "JsonJacksonCodec"
For example, i have written one based on our needs.

import org.redisson.client.codec.BaseCodec;
import org.redisson.client.protocol.Decoder;
import org.redisson.client.protocol.Encoder;

import io.netty.buffer.Unpooled;

/**
 * Encoder/Decoder for {@code Codec}.
 */
final class SnappyCodec extends BaseCodec {

    static final SnappyCodec INSTANCE = new SnappyCodec();

    private static final Encoder ENCODER = in -> Unpooled.wrappedBuffer(SnappyCompressor.getInstance().serializeAndCompress(in));

    private static final Decoder<Object> DECODER = (buf, state) -> {
        final byte[] result = new byte[buf.readableBytes()];
        buf.readBytes(result);
        return SnappyCompressor.getInstance().uncompressAndDeserializeWithFallbackToDeserializedDataBuffer(result);
    };

    @Override
    public Decoder<Object> getValueDecoder() {
        return DECODER;
    }

    @Override
    public Encoder getValueEncoder() {
        return ENCODER;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文