spullara / redis-protocol

Java client and server implementation of Redis
356 stars 134 forks source link

raw bytes[] not supported (due to vararg wrapping) #5

Closed costin closed 12 years ago

costin commented 12 years ago

Hi,

I took a first pass at integrating this project or as I call it SRP (Sam's Redis Protocol) into Spring Data Redis [1] and the biggest issue I encounter was the lack of support for passing raw byte[] to RedisClient. While the protocol supports this the use of varargs causes the passed byte[] to be wrapped in an Object[] which the protocol doesn't understand (and thus calls toString() on it).

The problem lies within the use of varargs between various methods and RedisClientBase#pipeline method.

Take mget - if you pass a byte[] it will gets wrapped in an Object[] automatically (Object[] {byte[]}) which For all commands RedisClient calls pipeline(CMD, CMD_as bytes, arguments) which get wrapped into an Object[] that gets sent to redisProtocol#sendAsync and further down to Command#writeDirect(). At this point Command receives Object[] { CMD as bytes, Object[] { byte[] } } - it knows how to handle CMD but it doesn't unwrap the Object[] and instead calls toString() on it. A simple fix would be to check for this wrapper or avoid it in the first place.

[1] https://github.com/SpringSource/spring-data-redis/tree/srp

spullara commented 12 years ago

My test coverage of the generated client is pretty abysmal right now, I've rejiggered it and have some tests for commands that take varargs. This also led to a efficiency improvement as we don't need to allocate during Command writing.

spullara commented 12 years ago

I've updated it and added a test that uses one of the varargs commands.