convertMulti method added

pull/243/head
Nikita 10 years ago
parent 3f55d2fc7a
commit ed33902085

@ -91,7 +91,7 @@ public class CommandDecoder extends ReplayingDecoder<Void> {
String result = in.readBytes(in.bytesBefore((byte) '\r')).toString(CharsetUtil.UTF_8);
in.skipBytes(2);
handleResult(data, parts, result);
handleResult(data, parts, result, false);
} else if (code == '-') {
String error = in.readBytes(in.bytesBefore((byte) '\r')).toString(CharsetUtil.UTF_8);
in.skipBytes(2);
@ -111,14 +111,14 @@ public class CommandDecoder extends ReplayingDecoder<Void> {
String status = in.readBytes(in.bytesBefore((byte) '\r')).toString(CharsetUtil.UTF_8);
in.skipBytes(2);
Object result = Long.valueOf(status);
handleResult(data, parts, result);
handleResult(data, parts, result, false);
} else if (code == '$') {
ByteBuf buf = readBytes(in);
Object result = null;
if (buf != null) {
result = decoder(data, parts, currentDecoder).decode(buf);
}
handleResult(data, parts, result);
handleResult(data, parts, result, false);
} else if (code == '*') {
long size = readLong(in);
List<Object> respParts = new ArrayList<Object>();
@ -160,11 +160,7 @@ public class CommandDecoder extends ReplayingDecoder<Void> {
}
}
if (parts != null) {
parts.add(result);
} else {
data.getPromise().setSuccess(result);
}
handleResult(data, parts, result, true);
} else {
RedisPubSubConnection pubSubConnection = (RedisPubSubConnection)channel.attr(RedisPubSubConnection.CONNECTION).get();
if (result instanceof PubSubMessage) {
@ -175,9 +171,13 @@ public class CommandDecoder extends ReplayingDecoder<Void> {
}
}
private void handleResult(CommandData<Object, Object> data, List<Object> parts, Object result) {
private void handleResult(CommandData<Object, Object> data, List<Object> parts, Object result, boolean multiResult) {
if (data != null) {
result = data.getCommand().getConvertor().convert(result);
if (multiResult) {
result = data.getCommand().getConvertor().convertMulti(result);
} else {
result = data.getCommand().getConvertor().convert(result);
}
}
if (parts != null) {
parts.add(result);

@ -15,7 +15,7 @@
*/
package org.redisson.client.protocol.convertor;
public class BooleanReplayConvertor implements Convertor<Boolean> {
public class BooleanReplayConvertor extends SingleConvertor<Boolean> {
@Override
public Boolean convert(Object obj) {

@ -17,6 +17,8 @@ package org.redisson.client.protocol.convertor;
public interface Convertor<R> {
Object convertMulti(Object obj);
R convert(Object obj);
}

@ -15,7 +15,7 @@
*/
package org.redisson.client.protocol.convertor;
public class EmptyConvertor<R> implements Convertor<R> {
public class EmptyConvertor<R> extends SingleConvertor<R> {
@Override
public R convert(Object obj) {

@ -15,7 +15,7 @@
*/
package org.redisson.client.protocol.convertor;
public class LongReplayConvertor implements Convertor<Long> {
public class LongReplayConvertor extends SingleConvertor<Long> {
@Override
public Long convert(Object obj) {

@ -0,0 +1,25 @@
/**
* Copyright 2014 Nikita Koksharov, Nickolay Borbit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.client.protocol.convertor;
public abstract class SingleConvertor<R> implements Convertor<R> {
@Override
public Object convertMulti(Object obj) {
return obj;
}
}

@ -15,7 +15,7 @@
*/
package org.redisson.client.protocol.convertor;
public class VoidReplayConvertor implements Convertor<Void> {
public class VoidReplayConvertor extends SingleConvertor<Void> {
@Override
public Void convert(Object obj) {

Loading…
Cancel
Save