Search in sources :

Example 1 with RedisOutOfMemoryException

use of org.redisson.client.RedisOutOfMemoryException in project redisson by redisson.

the class CommandDecoder method decode.

private void decode(ByteBuf in, CommandData<Object, Object> data, List<Object> parts, Channel channel) throws IOException {
    int code = in.readByte();
    if (code == '+') {
        ByteBuf rb = in.readBytes(in.bytesBefore((byte) '\r'));
        try {
            String result = rb.toString(CharsetUtil.UTF_8);
            in.skipBytes(2);
            handleResult(data, parts, result, false, channel);
        } finally {
            rb.release();
        }
    } else if (code == '-') {
        ByteBuf rb = in.readBytes(in.bytesBefore((byte) '\r'));
        try {
            String error = rb.toString(CharsetUtil.UTF_8);
            in.skipBytes(2);
            if (error.startsWith("MOVED")) {
                String[] errorParts = error.split(" ");
                int slot = Integer.valueOf(errorParts[1]);
                String addr = errorParts[2];
                data.tryFailure(new RedisMovedException(slot, addr));
            } else if (error.startsWith("ASK")) {
                String[] errorParts = error.split(" ");
                int slot = Integer.valueOf(errorParts[1]);
                String addr = errorParts[2];
                data.tryFailure(new RedisAskException(slot, addr));
            } else if (error.startsWith("TRYAGAIN")) {
                data.tryFailure(new RedisTryAgainException(error + ". channel: " + channel + " data: " + data));
            } else if (error.startsWith("LOADING")) {
                data.tryFailure(new RedisLoadingException(error + ". channel: " + channel + " data: " + data));
            } else if (error.startsWith("OOM")) {
                data.tryFailure(new RedisOutOfMemoryException(error.split("OOM ")[1] + ". channel: " + channel + " data: " + data));
            } else if (error.contains("-OOM ")) {
                data.tryFailure(new RedisOutOfMemoryException(error.split("-OOM ")[1] + ". channel: " + channel + " data: " + data));
            } else {
                if (data != null) {
                    data.tryFailure(new RedisException(error + ". channel: " + channel + " command: " + data));
                } else {
                    log.error("Error: {} channel: {} data: {}", error, channel, data);
                }
            }
        } finally {
            rb.release();
        }
    } else if (code == ':') {
        Long result = readLong(in);
        handleResult(data, parts, result, false, channel);
    } else if (code == '$') {
        ByteBuf buf = readBytes(in);
        Object result = null;
        if (buf != null) {
            Decoder<Object> decoder = selectDecoder(data, parts);
            result = decoder.decode(buf, state());
        }
        handleResult(data, parts, result, false, channel);
    } else if (code == '*') {
        int level = state().incLevel();
        long size = readLong(in);
        List<Object> respParts;
        if (state().getLevels().size() - 1 >= level) {
            StateLevel stateLevel = state().getLevels().get(level);
            respParts = stateLevel.getParts();
            size = stateLevel.getSize();
        } else {
            respParts = new ArrayList<Object>();
            if (state().isMakeCheckpoint()) {
                state().addLevel(new StateLevel(size, respParts));
            }
        }
        decodeList(in, data, parts, channel, size, respParts);
    } else {
        String dataStr = in.toString(0, in.writerIndex(), CharsetUtil.UTF_8);
        throw new IllegalStateException("Can't decode replay: " + dataStr);
    }
}
Also used : RedisMovedException(org.redisson.client.RedisMovedException) RedisTryAgainException(org.redisson.client.RedisTryAgainException) ByteBuf(io.netty.buffer.ByteBuf) ReplayingDecoder(io.netty.handler.codec.ReplayingDecoder) Decoder(org.redisson.client.protocol.Decoder) ListMultiDecoder(org.redisson.client.protocol.decoder.ListMultiDecoder) SlotsDecoder(org.redisson.client.protocol.decoder.SlotsDecoder) NestedMultiDecoder(org.redisson.client.protocol.decoder.NestedMultiDecoder) MultiDecoder(org.redisson.client.protocol.decoder.MultiDecoder) RedisLoadingException(org.redisson.client.RedisLoadingException) RedisException(org.redisson.client.RedisException) RedisAskException(org.redisson.client.RedisAskException) RedisOutOfMemoryException(org.redisson.client.RedisOutOfMemoryException)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 ReplayingDecoder (io.netty.handler.codec.ReplayingDecoder)1 RedisAskException (org.redisson.client.RedisAskException)1 RedisException (org.redisson.client.RedisException)1 RedisLoadingException (org.redisson.client.RedisLoadingException)1 RedisMovedException (org.redisson.client.RedisMovedException)1 RedisOutOfMemoryException (org.redisson.client.RedisOutOfMemoryException)1 RedisTryAgainException (org.redisson.client.RedisTryAgainException)1 Decoder (org.redisson.client.protocol.Decoder)1 ListMultiDecoder (org.redisson.client.protocol.decoder.ListMultiDecoder)1 MultiDecoder (org.redisson.client.protocol.decoder.MultiDecoder)1 NestedMultiDecoder (org.redisson.client.protocol.decoder.NestedMultiDecoder)1 SlotsDecoder (org.redisson.client.protocol.decoder.SlotsDecoder)1