diff --git a/src/main/java/org/redisson/client/RedisClient.java b/src/main/java/org/redisson/client/RedisClient.java index 0f227798c..c14ac912b 100644 --- a/src/main/java/org/redisson/client/RedisClient.java +++ b/src/main/java/org/redisson/client/RedisClient.java @@ -105,15 +105,15 @@ public class RedisClient { RedisConnection rc = c.connect(); RedisPubSubConnection rpsc = c.connectPubSub(); -// String res1 = rc.sync(RedisCommands.CLIENT_SETNAME, "12333"); -// System.out.println("res 12: " + res1); -// String res2 = rc.sync(RedisCommands.CLIENT_GETNAME); -// System.out.println("res name: " + res2); + String res1 = rc.sync(RedisCommands.CLIENT_SETNAME, "12333"); + System.out.println("res 12: " + res1); + String res2 = rc.sync(RedisCommands.CLIENT_GETNAME); + System.out.println("res name: " + res2); // Boolean res3 = rc.sync(new StringCodec(), RedisCommands.EXISTS, "33"); // System.out.println("res name 2: " + res3); - Future m = rpsc.publish("sss", "123"); - System.out.println("out: " + m.get()); + Long m = rc.sync(new StringCodec(), RedisCommands.PUBLISH, "sss", "123"); + System.out.println("out: " + m); Future m1 = rpsc.psubscribe("ss*"); System.out.println("out: " + m1.get()); rpsc.addListener(new RedisPubSubListener() { @@ -133,7 +133,7 @@ public class RedisClient { final RedisClient c2 = new RedisClient("127.0.0.1", 6379); Long res = c2.connect().sync(new StringCodec(), RedisCommands.PUBLISH, "sss", "4444"); -// System.out.println("published: " + res); + System.out.println("published: " + res); diff --git a/src/main/java/org/redisson/client/RedisConnection.java b/src/main/java/org/redisson/client/RedisConnection.java index 97d006ee5..7fa46efc0 100644 --- a/src/main/java/org/redisson/client/RedisConnection.java +++ b/src/main/java/org/redisson/client/RedisConnection.java @@ -6,7 +6,7 @@ import org.redisson.client.handler.RedisData; import org.redisson.client.protocol.Codec; import org.redisson.client.protocol.RedisCommand; import org.redisson.client.protocol.RedisCommands; -import org.redisson.client.protocol.RedisStringCommand; +import org.redisson.client.protocol.RedisStrictCommand; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -56,17 +56,11 @@ public class RedisConnection implements RedisCommands { throw new RedisException("Unexpected exception while processing command", future.cause()); } - public String sync(RedisStringCommand command, Object ... params) { - Future r = async(command, params); + public T sync(RedisStrictCommand command, Object ... params) { + Future r = async(null, command, params); return await(r); } - public Future async(RedisStringCommand command, Object ... params) { - Promise promise = redisClient.getBootstrap().group().next().newPromise(); - channel.writeAndFlush(new RedisData(promise, command.getCodec(), command, params)); - return promise; - } - public void send(RedisData data) { channel.writeAndFlush(data); } diff --git a/src/main/java/org/redisson/client/RedisPubSubConnection.java b/src/main/java/org/redisson/client/RedisPubSubConnection.java index e89bf52fa..fafc72c0a 100644 --- a/src/main/java/org/redisson/client/RedisPubSubConnection.java +++ b/src/main/java/org/redisson/client/RedisPubSubConnection.java @@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; import org.redisson.client.handler.RedisData; import org.redisson.client.protocol.Codec; import org.redisson.client.protocol.Decoder; +import org.redisson.client.protocol.MultiDecoder; import org.redisson.client.protocol.PubSubStatusMessage; import org.redisson.client.protocol.PubSubStatusDecoder; import org.redisson.client.protocol.PubSubMessage; @@ -54,30 +55,26 @@ public class RedisPubSubConnection { } public Future subscribe(String ... channel) { - return async(new PubSubStatusDecoder(), new PubSubMessageDecoder(), RedisCommands.SUBSCRIBE, channel); + return async(new PubSubMessageDecoder(), RedisCommands.SUBSCRIBE, channel); } public Future psubscribe(String ... channel) { - return async(new PubSubStatusDecoder(), new PubSubPatternMessageDecoder(), RedisCommands.PSUBSCRIBE, channel); + return async(new PubSubPatternMessageDecoder(), RedisCommands.PSUBSCRIBE, channel); } public Future unsubscribe(String ... channel) { - return async(new PubSubStatusDecoder(), RedisCommands.SUBSCRIBE, channel); + return async(null, RedisCommands.UNSUBSCRIBE, channel); } - public Future publish(String channel, String msg) { - return async(new StringCodec(), RedisCommands.PUBLISH, channel, msg); - } - - public Future async(Codec encoder, RedisCommand command, Object ... params) { - Promise promise = redisClient.getBootstrap().group().next().newPromise(); - channel.writeAndFlush(new RedisData(promise, encoder, command, params)); - return promise; - } +// public Future async(Codec encoder, RedisCommand command, Object ... params) { +// Promise promise = redisClient.getBootstrap().group().next().newPromise(); +// channel.writeAndFlush(new RedisData(promise, encoder, command, params)); +// return promise; +// } - public Future async(Codec encoder, Decoder nextDecoder, RedisCommand command, Object ... params) { + public Future async(MultiDecoder nextDecoder, RedisCommand command, Object ... params) { Promise promise = redisClient.getBootstrap().group().next().newPromise(); - channel.writeAndFlush(new RedisData(promise, nextDecoder, encoder, command, params)); + channel.writeAndFlush(new RedisData(promise, nextDecoder, null, command, params)); return promise; } diff --git a/src/main/java/org/redisson/client/handler/RedisData.java b/src/main/java/org/redisson/client/handler/RedisData.java index c8fcf41eb..61bca58f3 100644 --- a/src/main/java/org/redisson/client/handler/RedisData.java +++ b/src/main/java/org/redisson/client/handler/RedisData.java @@ -19,6 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.redisson.client.protocol.Codec; import org.redisson.client.protocol.Decoder; +import org.redisson.client.protocol.MultiDecoder; import org.redisson.client.protocol.RedisCommand; import io.netty.util.concurrent.Promise; @@ -30,13 +31,13 @@ public class RedisData { final Object[] params; final Codec codec; final AtomicBoolean sended = new AtomicBoolean(); - final Decoder nextDecoder; + final MultiDecoder nextDecoder; public RedisData(Promise promise, Codec codec, RedisCommand command, Object[] params) { this(promise, null, codec, command, params); } - public RedisData(Promise promise, Decoder nextDecoder, Codec codec, RedisCommand command, Object[] params) { + public RedisData(Promise promise, MultiDecoder nextDecoder, Codec codec, RedisCommand command, Object[] params) { this.promise = promise; this.command = command; this.params = params; @@ -52,7 +53,7 @@ public class RedisData { return params; } - public Decoder getNextDecoder() { + public MultiDecoder getNextDecoder() { return nextDecoder; } diff --git a/src/main/java/org/redisson/client/handler/RedisDecoder.java b/src/main/java/org/redisson/client/handler/RedisDecoder.java index b0507fd0e..42d52054d 100644 --- a/src/main/java/org/redisson/client/handler/RedisDecoder.java +++ b/src/main/java/org/redisson/client/handler/RedisDecoder.java @@ -24,6 +24,7 @@ import org.redisson.client.RedisException; import org.redisson.client.RedisPubSubConnection; import org.redisson.client.handler.RedisCommandsQueue.QueueCommands; import org.redisson.client.protocol.Decoder; +import org.redisson.client.protocol.MultiDecoder; import org.redisson.client.protocol.PubSubMessage; import org.redisson.client.protocol.PubSubPatternMessage; @@ -38,7 +39,7 @@ public class RedisDecoder extends ReplayingDecoder { public static final char LF = '\n'; private static final char ZERO = '0'; - private Decoder nextDecoder; + private MultiDecoder nextDecoder; @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { @@ -54,33 +55,19 @@ public class RedisDecoder extends ReplayingDecoder { int code = in.readByte(); // System.out.println("trying decode -- " + (char)code); if (code == '+') { - Object result = data.getCommand().getReponseDecoder().decode(in); - if (parts != null) { - parts.add(result); - } else { - data.getPromise().setSuccess(result); - } + Object result = data.getCommand().getReplayDecoder().decode(in); + handleResult(data, parts, result); } else if (code == '-') { - Object result = data.getCommand().getReponseDecoder().decode(in); + Object result = data.getCommand().getReplayDecoder().decode(in); data.getPromise().setFailure(new RedisException(result.toString())); } else if (code == ':') { String status = in.readBytes(in.bytesBefore((byte) '\r')).toString(CharsetUtil.UTF_8); in.skipBytes(2); Object result = Long.valueOf(status); - result = data.getCommand().getConvertor().convert(result); - - if (parts != null) { - parts.add(result); - } else { - data.getPromise().setSuccess(result); - } + handleResult(data, parts, result); } else if (code == '$') { - Object result = decoder(data).decode(readBytes(in)); - if (parts != null) { - parts.add(result); - } else { - data.getPromise().setSuccess(result); - } + Object result = decoder(data, parts != null).decode(readBytes(in)); + handleResult(data, parts, result); } else if (code == '*') { long size = readLong(in); List respParts = new ArrayList(); @@ -88,7 +75,7 @@ public class RedisDecoder extends ReplayingDecoder { decode(in, data, respParts, pubSubConnection); } - Object result = decoder(data).decode(respParts); + Object result = ((MultiDecoder)decoder(data, true)).decode(respParts); if (data != null) { if (Arrays.asList("PSUBSCRIBE", "SUBSCRIBE").contains(data.getCommand().getName())) { nextDecoder = data.getNextDecoder(); @@ -106,11 +93,25 @@ public class RedisDecoder extends ReplayingDecoder { } } - private Decoder decoder(RedisData data) { + private void handleResult(RedisData data, List parts, Object result) { + if (data != null) { + result = data.getCommand().getConvertor().convert(result); + } + if (parts != null) { + parts.add(result); + } else { + data.getPromise().setSuccess(result); + } + } + + private Decoder decoder(RedisData data, boolean isMulti) { if (data == null) { return nextDecoder; } - Decoder decoder = data.getCommand().getReponseDecoder(); + Decoder decoder = data.getCommand().getReplayDecoder(); + if (isMulti) { + decoder = data.getCommand().getReplayMultiDecoder(); + } if (decoder == null) { decoder = data.getCodec(); } diff --git a/src/main/java/org/redisson/client/handler/RedisEncoder.java b/src/main/java/org/redisson/client/handler/RedisEncoder.java index 5f712bc79..735ea6eb3 100644 --- a/src/main/java/org/redisson/client/handler/RedisEncoder.java +++ b/src/main/java/org/redisson/client/handler/RedisEncoder.java @@ -20,7 +20,6 @@ import java.util.Arrays; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -import io.netty.util.CharsetUtil; public class RedisEncoder extends MessageToByteEncoder> { @@ -44,8 +43,10 @@ public class RedisEncoder extends MessageToByteEncoder } int i = 1; for (Object param : msg.getParams()) { - if (Arrays.binarySearch(msg.getCommand().getEncodeParamIndexes(), i) != -1) { + if (Arrays.binarySearch(msg.getCommand().getObjectParamIndexes(), i) != -1) { writeArgument(out, msg.getCodec().encode(i, param)); + } else { + writeArgument(out, msg.getCommand().getParamsEncoder().encode(i, param)); } i++; } diff --git a/src/main/java/org/redisson/client/protocol/BooleanReplayConvertor.java b/src/main/java/org/redisson/client/protocol/BooleanReplayConvertor.java index 62ddbd1c5..485685a0f 100644 --- a/src/main/java/org/redisson/client/protocol/BooleanReplayConvertor.java +++ b/src/main/java/org/redisson/client/protocol/BooleanReplayConvertor.java @@ -19,7 +19,7 @@ public class BooleanReplayConvertor implements Convertor { @Override public Boolean convert(Object obj) { - return "1".equals(obj); + return Long.valueOf(1).equals(obj); } diff --git a/src/main/java/org/redisson/client/protocol/Decoder.java b/src/main/java/org/redisson/client/protocol/Decoder.java index 7f1f672fc..7f8f22b2c 100644 --- a/src/main/java/org/redisson/client/protocol/Decoder.java +++ b/src/main/java/org/redisson/client/protocol/Decoder.java @@ -15,14 +15,10 @@ */ package org.redisson.client.protocol; -import java.util.List; - import io.netty.buffer.ByteBuf; public interface Decoder { R decode(ByteBuf buf); - R decode(List parts); - } diff --git a/src/main/java/org/redisson/client/protocol/MultiDecoder.java b/src/main/java/org/redisson/client/protocol/MultiDecoder.java new file mode 100644 index 000000000..4dee5f005 --- /dev/null +++ b/src/main/java/org/redisson/client/protocol/MultiDecoder.java @@ -0,0 +1,9 @@ +package org.redisson.client.protocol; + +import java.util.List; + +public interface MultiDecoder extends Decoder { + + T decode(List parts); + +} diff --git a/src/main/java/org/redisson/client/protocol/PubSubMessageDecoder.java b/src/main/java/org/redisson/client/protocol/PubSubMessageDecoder.java index a4ddd5728..9898407fd 100644 --- a/src/main/java/org/redisson/client/protocol/PubSubMessageDecoder.java +++ b/src/main/java/org/redisson/client/protocol/PubSubMessageDecoder.java @@ -5,7 +5,7 @@ import java.util.List; import io.netty.buffer.ByteBuf; import io.netty.util.CharsetUtil; -public class PubSubMessageDecoder implements Decoder { +public class PubSubMessageDecoder implements MultiDecoder { @Override public Object decode(ByteBuf buf) { @@ -15,7 +15,7 @@ public class PubSubMessageDecoder implements Decoder { } @Override - public Object decode(List parts) { + public PubSubMessage decode(List parts) { return new PubSubMessage(parts.get(1).toString(), parts.get(2).toString()); } diff --git a/src/main/java/org/redisson/client/protocol/PubSubPatternMessageDecoder.java b/src/main/java/org/redisson/client/protocol/PubSubPatternMessageDecoder.java index 0e7064791..1aa2a6c2a 100644 --- a/src/main/java/org/redisson/client/protocol/PubSubPatternMessageDecoder.java +++ b/src/main/java/org/redisson/client/protocol/PubSubPatternMessageDecoder.java @@ -5,7 +5,7 @@ import java.util.List; import io.netty.buffer.ByteBuf; import io.netty.util.CharsetUtil; -public class PubSubPatternMessageDecoder implements Decoder { +public class PubSubPatternMessageDecoder implements MultiDecoder { @Override public Object decode(ByteBuf buf) { @@ -15,7 +15,7 @@ public class PubSubPatternMessageDecoder implements Decoder { } @Override - public Object decode(List parts) { + public PubSubPatternMessage decode(List parts) { return new PubSubPatternMessage(parts.get(1).toString(), parts.get(2).toString(), parts.get(3)); } diff --git a/src/main/java/org/redisson/client/protocol/PubSubStatusDecoder.java b/src/main/java/org/redisson/client/protocol/PubSubStatusDecoder.java index 3137ec7c2..f1838bea4 100644 --- a/src/main/java/org/redisson/client/protocol/PubSubStatusDecoder.java +++ b/src/main/java/org/redisson/client/protocol/PubSubStatusDecoder.java @@ -15,17 +15,16 @@ */ package org.redisson.client.protocol; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import io.netty.buffer.ByteBuf; import io.netty.util.CharsetUtil; -public class PubSubStatusDecoder implements Codec { +public class PubSubStatusDecoder implements MultiDecoder { @Override - public String decode(ByteBuf buf) { + public Object decode(ByteBuf buf) { String status = buf.toString(CharsetUtil.UTF_8); buf.skipBytes(2); return status; @@ -40,13 +39,4 @@ public class PubSubStatusDecoder implements Codec { return new PubSubStatusMessage(PubSubStatusMessage.Type.valueOf(parts.get(0).toString().toUpperCase()), channels); } - @Override - public byte[] encode(int paramIndex, Object in) { - try { - return in.toString().getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } - } diff --git a/src/main/java/org/redisson/client/protocol/RedisCommand.java b/src/main/java/org/redisson/client/protocol/RedisCommand.java index ca8ad9918..0943fd285 100644 --- a/src/main/java/org/redisson/client/protocol/RedisCommand.java +++ b/src/main/java/org/redisson/client/protocol/RedisCommand.java @@ -19,8 +19,11 @@ public class RedisCommand { private final String name; private final String subName; - private final int[] encodeParamIndexes; - private Decoder reponseDecoder; + private final int[] objectParamIndexes; + + private Encoder paramsEncoder = new StringParamsEncoder(); + private MultiDecoder replayMultiDecoder; + private Decoder replayDecoder; private Convertor convertor = new EmptyConvertor(); public RedisCommand(String name, String subName, int ... encodeParamIndexes) { @@ -34,7 +37,7 @@ public class RedisCommand { public RedisCommand(String name, Convertor convertor, int ... encodeParamIndexes) { this.name = name; this.subName = null; - this.encodeParamIndexes = encodeParamIndexes; + this.objectParamIndexes = encodeParamIndexes; this.convertor = convertor; } @@ -42,12 +45,19 @@ public class RedisCommand { this(name, null, reponseDecoder, encodeParamIndexes); } + public RedisCommand(String name, MultiDecoder replayMultiDecoder, int ... encodeParamIndexes) { + this.name = name; + this.subName = null; + this.objectParamIndexes = encodeParamIndexes; + this.replayMultiDecoder = replayMultiDecoder; + } + public RedisCommand(String name, String subName, Decoder reponseDecoder, int ... encodeParamIndexes) { super(); this.name = name; this.subName = subName; - this.reponseDecoder = reponseDecoder; - this.encodeParamIndexes = encodeParamIndexes; + this.replayDecoder = reponseDecoder; + this.objectParamIndexes = encodeParamIndexes; } public String getSubName() { @@ -58,16 +68,24 @@ public class RedisCommand { return name; } - public Decoder getReponseDecoder() { - return reponseDecoder; + public Decoder getReplayDecoder() { + return replayDecoder; } - public int[] getEncodeParamIndexes() { - return encodeParamIndexes; + public int[] getObjectParamIndexes() { + return objectParamIndexes; + } + + public MultiDecoder getReplayMultiDecoder() { + return replayMultiDecoder; } public Convertor getConvertor() { return convertor; } + public Encoder getParamsEncoder() { + return paramsEncoder; + } + } diff --git a/src/main/java/org/redisson/client/protocol/RedisCommands.java b/src/main/java/org/redisson/client/protocol/RedisCommands.java index 985e3d049..ee581021f 100644 --- a/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -17,20 +17,21 @@ package org.redisson.client.protocol; public interface RedisCommands { - RedisStringCommand AUTH = new RedisStringCommand("AUTH", new StringReplayDecoder()); - RedisStringCommand SELECT = new RedisStringCommand("SELECT", new StringReplayDecoder()); - RedisStringCommand CLIENT_SETNAME = new RedisStringCommand("CLIENT", "SETNAME", new StringReplayDecoder(), 1); - RedisStringCommand CLIENT_GETNAME = new RedisStringCommand("CLIENT", "GETNAME"); + RedisStrictCommand AUTH = new RedisStrictCommand("AUTH", new StringReplayDecoder()); + RedisStrictCommand SELECT = new RedisStrictCommand("SELECT", new StringReplayDecoder()); + RedisStrictCommand CLIENT_SETNAME = new RedisStrictCommand("CLIENT", "SETNAME", new StringReplayDecoder()); + RedisStrictCommand CLIENT_GETNAME = new RedisStrictCommand("CLIENT", "GETNAME", new StringDataDecoder()); RedisCommand GET = new RedisCommand("GET"); RedisCommand SET = new RedisCommand("SET", new StringReplayDecoder(), 1); RedisCommand SETEX = new RedisCommand("SETEX", new StringReplayDecoder(), 2); - RedisCommand EXISTS = new RedisCommand("EXISTS", new BooleanReplayConvertor(), 1); + RedisStrictCommand EXISTS = new RedisStrictCommand("EXISTS", new BooleanReplayConvertor()); RedisCommand PUBLISH = new RedisCommand("PUBLISH", 1); - RedisCommand SUBSCRIBE = new RedisCommand("SUBSCRIBE", 1); - RedisCommand UNSUBSCRIBE = new RedisCommand("UNSUBSCRIBE", 1); - RedisCommand PSUBSCRIBE = new RedisCommand("PSUBSCRIBE", 1); + RedisStrictCommand SUBSCRIBE = new RedisStrictCommand("SUBSCRIBE", new PubSubStatusDecoder()); + RedisStrictCommand UNSUBSCRIBE = new RedisStrictCommand("UNSUBSCRIBE", new PubSubStatusDecoder()); + RedisStrictCommand PSUBSCRIBE = new RedisStrictCommand("PSUBSCRIBE", new PubSubStatusDecoder()); + RedisStrictCommand PUNSUBSCRIBE = new RedisStrictCommand("PUNSUBSCRIBE", new PubSubStatusDecoder()); } diff --git a/src/main/java/org/redisson/client/protocol/RedisStrictCommand.java b/src/main/java/org/redisson/client/protocol/RedisStrictCommand.java new file mode 100644 index 000000000..b71796ee3 --- /dev/null +++ b/src/main/java/org/redisson/client/protocol/RedisStrictCommand.java @@ -0,0 +1,30 @@ +package org.redisson.client.protocol; + +public class RedisStrictCommand extends RedisCommand { + + public RedisStrictCommand(String name, MultiDecoder replayMultiDecoder, int... encodeParamIndexes) { + super(name, replayMultiDecoder, encodeParamIndexes); + } + + public RedisStrictCommand(String name, int... encodeParamIndexes) { + super(name, encodeParamIndexes); + } + + public RedisStrictCommand(String name, Convertor convertor, int ... encodeParamIndexes) { + super(name, convertor, encodeParamIndexes); + } + + public RedisStrictCommand(String name, String subName, Decoder reponseDecoder, + int... encodeParamIndexes) { + super(name, subName, reponseDecoder, encodeParamIndexes); + } + + public RedisStrictCommand(String name, String subName, int... encodeParamIndexes) { + super(name, subName, encodeParamIndexes); + } + + public RedisStrictCommand(String name, Decoder reponseDecoder, int... encodeParamIndexes) { + super(name, reponseDecoder, encodeParamIndexes); + } + +} diff --git a/src/main/java/org/redisson/client/protocol/RedisStringCommand.java b/src/main/java/org/redisson/client/protocol/RedisStringCommand.java deleted file mode 100644 index bb0b2cc43..000000000 --- a/src/main/java/org/redisson/client/protocol/RedisStringCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.redisson.client.protocol; - -public class RedisStringCommand extends RedisCommand { - - private Codec codec = new StringCodec(); - - public RedisStringCommand(String name, int... encodeParamIndexes) { - super(name, encodeParamIndexes); - } - - public RedisStringCommand(String name, String subName, Decoder reponseDecoder, - int... encodeParamIndexes) { - super(name, subName, reponseDecoder, encodeParamIndexes); - } - - public RedisStringCommand(String name, String subName, int... encodeParamIndexes) { - super(name, subName, encodeParamIndexes); - } - - public RedisStringCommand(String name, Decoder reponseDecoder, int... encodeParamIndexes) { - super(name, reponseDecoder, encodeParamIndexes); - } - - public Codec getCodec() { - return codec; - } - -} diff --git a/src/main/java/org/redisson/client/protocol/StringCodec.java b/src/main/java/org/redisson/client/protocol/StringCodec.java index 3554427c9..4db8fa9c6 100644 --- a/src/main/java/org/redisson/client/protocol/StringCodec.java +++ b/src/main/java/org/redisson/client/protocol/StringCodec.java @@ -1,7 +1,6 @@ package org.redisson.client.protocol; import java.io.UnsupportedEncodingException; -import java.util.List; import io.netty.buffer.ByteBuf; import io.netty.util.CharsetUtil; @@ -22,9 +21,4 @@ public class StringCodec implements Codec { return buf.toString(CharsetUtil.UTF_8); } - @Override - public Object decode(List parts) { - throw new IllegalStateException(); - } - } diff --git a/src/main/java/org/redisson/client/protocol/StringDataDecoder.java b/src/main/java/org/redisson/client/protocol/StringDataDecoder.java new file mode 100644 index 000000000..cdd929bf4 --- /dev/null +++ b/src/main/java/org/redisson/client/protocol/StringDataDecoder.java @@ -0,0 +1,28 @@ +/** + * 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; + +import io.netty.buffer.ByteBuf; +import io.netty.util.CharsetUtil; + +public class StringDataDecoder implements Decoder { + + @Override + public String decode(ByteBuf buf) { + return buf.toString(CharsetUtil.UTF_8); + } + +} diff --git a/src/main/java/org/redisson/client/protocol/StringParamsEncoder.java b/src/main/java/org/redisson/client/protocol/StringParamsEncoder.java new file mode 100644 index 000000000..17e0c7518 --- /dev/null +++ b/src/main/java/org/redisson/client/protocol/StringParamsEncoder.java @@ -0,0 +1,16 @@ +package org.redisson.client.protocol; + +import java.io.UnsupportedEncodingException; + +public class StringParamsEncoder implements Encoder { + + @Override + public byte[] encode(int paramIndex, Object in) { + try { + return in.toString().getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + } + +} diff --git a/src/main/java/org/redisson/client/protocol/StringReplayDecoder.java b/src/main/java/org/redisson/client/protocol/StringReplayDecoder.java index ba4ceae0f..05d841794 100644 --- a/src/main/java/org/redisson/client/protocol/StringReplayDecoder.java +++ b/src/main/java/org/redisson/client/protocol/StringReplayDecoder.java @@ -15,8 +15,6 @@ */ package org.redisson.client.protocol; -import java.util.List; - import io.netty.buffer.ByteBuf; import io.netty.util.CharsetUtil; @@ -29,9 +27,4 @@ public class StringReplayDecoder implements Decoder { return status; } - @Override - public String decode(List parts) { - throw new IllegalStateException(); - } - }