alphazero / jredis

Java Client and Connectors for Redis
http://code.google.com/p/jredis/
Apache License 2.0
315 stars 136 forks source link

add support for 2.2 (new unified request protocol) #49

Closed rajatm closed 13 years ago

rajatm commented 13 years ago

Can the support for latest redis release 2.2.2 be added?

I have modified the code in ProtocolBase to support the new unified request protocol http://redis.io/topics/protocol by just replacing the method createRequest by following:

public Request createRequest(Command cmd, byte[]... args) throws ProviderException, IllegalArgumentException {

    ByteArrayOutputStream buffer = createRequestBufffer (cmd);

    try {
        int argsCount = 1;
        if(args != null) {
            argsCount += args.length;
        }
        buffer.write(COUNT_BYTE);
        buffer.write(Convert.toBytes(argsCount));
        buffer.write(CRLF);

        buffer.write(SIZE_BYTE);
        buffer.write(Convert.toBytes(cmd.bytes.length));
        buffer.write(CRLF);
        buffer.write(cmd.bytes);
        buffer.write(CRLF);

        for(int s=0; s<args.length; s++){
            buffer.write(SIZE_BYTE);
            buffer.write(Convert.toBytes(args[s].length));
            buffer.write(CRLF);
            buffer.write(args[s]);
            buffer.write(CRLF);
        }
    } catch (Exception e) {
        throw new ProviderException("Problem writing to the buffer" + e.getLocalizedMessage());
    }
    return createRequest(buffer);
}

As of now it seems to be working fine at least for Synch Connection. Please check and incorporate if fine.

alphazero commented 13 years ago

Give the trunk another try. Its up to Redsi 2.2.4