### Question:
RedisRequestEncoder extends MessageToByteEncoder<RedisCommand> { @Override protected void encode(ChannelHandlerContext ctx, RedisCommand msg, ByteBuf out) throws Exception { msg.encode(out); if(logger.isDebugEnabled()){ logger.debug("request编码后协议文本内容:{}",out.toString(CharsetUtil.UTF_8).replaceAll("\r\n","\\\\r\\\\n")); } }    }### Answer:
@Test public void encode() { ByteBuf buf = Unpooled.buffer();; RedisCommand redisCommand = new RedisCommand(); redisCommand.setArgCount(3); List<byte[]> args = new ArrayList<>(); args.add("set".getBytes()); args.add("mykey".getBytes()); args.add("myvalue".getBytes()); redisCommand.setArgs(args); EmbeddedChannel channel = new EmbeddedChannel(new RedisRequestEncoder()); assertTrue(channel.writeOutbound(redisCommand)); assertTrue(channel.finish()); ByteBuf out = channel.readOutbound(); assertNotNull(out); assertEquals("*3",readToStr(out,2)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); assertEquals("$3",readToStr(out,2)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); assertEquals("set",readToStr(out,3)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); assertEquals("$5",readToStr(out,2)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); assertEquals("mykey",readToStr(out,5)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); assertEquals("$7",readToStr(out,2)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); assertEquals("myvalue",readToStr(out,7)); assertEquals(RedisConstants.CR_BYTE,(char)out.readByte()); assertEquals(RedisConstants.LF_BYTE,(char)out.readByte()); }