ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shro...@apache.org
Subject ignite git commit: IGNITE-2788: Basic Redis protocol implementation. Added SETRANGE and GETRANGE commands.
Date Wed, 27 Apr 2016 08:16:05 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2788 998cf4da7 -> 62d5cafed


IGNITE-2788: Basic Redis protocol implementation. Added SETRANGE and GETRANGE commands.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/62d5cafe
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/62d5cafe
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/62d5cafe

Branch: refs/heads/ignite-2788
Commit: 62d5cafed207c1a153f9e90fdaca801833e1999f
Parents: 998cf4d
Author: shtykh_roman <rshtykh@yahoo.com>
Authored: Wed Apr 27 17:09:14 2016 +0900
Committer: shtykh_roman <rshtykh@yahoo.com>
Committed: Wed Apr 27 17:09:14 2016 +0900

----------------------------------------------------------------------
 .../processors/redis/RedisProtocolSelfTest.java |  50 +++++++
 .../protocols/tcp/redis/GridRedisCommand.java   |   9 +-
 .../protocols/tcp/redis/GridRedisMessage.java   |  74 +++++++++--
 .../tcp/redis/GridRedisNioListener.java         |   4 +
 .../handler/GridRedisStringCommandHandler.java  |  17 +--
 .../string/GridRedisAppendCommandHandler.java   |   8 +-
 .../string/GridRedisGetCommandHandler.java      |   3 +-
 .../string/GridRedisGetRangeCommandHandler.java | 124 ++++++++++++++++++
 .../string/GridRedisGetSetCommandHandler.java   |   7 +-
 .../string/GridRedisIncrDecrCommandHandler.java |   8 +-
 .../string/GridRedisMGetCommandHandler.java     |   4 +-
 .../string/GridRedisMSetCommandHandler.java     |   4 +-
 .../string/GridRedisSetCommandHandler.java      |  14 +-
 .../string/GridRedisSetRangeCommandHandler.java | 131 +++++++++++++++++++
 .../string/GridRedisStrlenCommandHandler.java   |   3 +-
 15 files changed, 421 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/clients/src/test/java/org/apache/ignite/internal/processors/redis/RedisProtocolSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/redis/RedisProtocolSelfTest.java
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/redis/RedisProtocolSelfTest.java
index 0d27558..0f741b8 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/redis/RedisProtocolSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/redis/RedisProtocolSelfTest.java
@@ -309,4 +309,54 @@ public class RedisProtocolSelfTest extends GridCommonAbstractTest {
             Assert.assertEquals(3, (long)jedis.strlen("strlenKey"));
         }
     }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSetRange() throws Exception {
+        try (Jedis jedis = pool.getResource()) {
+            Assert.assertEquals(0, (long)jedis.setrange("setRangeKey1", 0, ""));
+
+            jcache().put("setRangeKey2", "abc");
+            Assert.assertEquals(3, (long)jedis.setrange("setRangeKey2", 0, ""));
+
+            Assert.assertEquals(3, (long)jedis.setrange("setRangeKeyPadded", 2, "a"));
+
+            try {
+                jedis.setrange("setRangeKeyWrongOffset", -1, "a");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("ERR"));
+            }
+
+            try {
+                jedis.setrange("setRangeKeyWrongOffset2", 536870911, "a");
+
+                assert false : "Exception has to be thrown!";
+            }
+            catch (JedisDataException e) {
+                assertTrue(e.getMessage().startsWith("ERR"));
+            }
+
+            jcache().put("setRangeKey3", "Hello World");
+            Assert.assertEquals(11, (long)jedis.setrange("setRangeKey3", 6, "Redis"));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetRange() throws Exception {
+        try (Jedis jedis = pool.getResource()) {
+            Assert.assertEquals("", jedis.getrange("getRangeKeyNonExisting", 0, 0));
+
+            jcache().put("getRangeKey", "This is a string");
+            Assert.assertEquals("This", jedis.getrange("getRangeKey", 0, 3));
+            Assert.assertEquals("ing", jedis.getrange("getRangeKey", -3, -1));
+            Assert.assertEquals("This is a string", jedis.getrange("getRangeKey", 0, -1));
+            Assert.assertEquals("string", jedis.getrange("getRangeKey", 10, 100));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisCommand.java
index 8e7e6a8..4684670 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisCommand.java
@@ -31,6 +31,7 @@ public enum GridRedisCommand {
     /** Echo. */
     ECHO("ECHO"),
 
+    // String commands.
     /** GET. */
     GET("GET"),
     /** MGET. */
@@ -47,14 +48,16 @@ public enum GridRedisCommand {
     INCRBY("INCRBY"),
     /** DECRBY. */
     DECRBY("DECRBY"),
-    /** INCRBYFLOAT. */
-    INCRBYFLOAT("INCRBYFLOAT"),
     /** APPEND. */
     APPEND("APPEND"),
     /** STRLEN. */
     STRLEN("STRLEN"),
     /** GETSET. */
-    GETSET("GETSET");
+    GETSET("GETSET"),
+    /** SETRANGE. */
+    SETRANGE("SETRANGE"),
+    /** GETRANGE. */
+    GETRANGE("GETRANGE");
 
     /** String for command. */
     private final String cmd;

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisMessage.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisMessage.java
index 20defb0..5f9eee1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisMessage.java
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.UUID;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.internal.processors.rest.client.message.GridClientMessage;
-import org.apache.ignite.internal.processors.rest.request.RestQueryRequest;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -39,17 +38,29 @@ public class GridRedisMessage implements GridClientMessage {
     /** Request byte. */
     public static final byte RESP_REQ_FLAG = GridRedisProtocolParser.ARRAY;
 
+    /** Command index. */
     private static final int CMD_POS = 0;
 
+    /** Key index. */
     private static final int KEY_POS = 1;
 
+    /** Auxiliary parameters offset. */
+    private static final int AUX_OFFSET = 2;
+
     /** Request message parts. */
     private final List<String> msgParts;
 
+    /** Response. */
     private ByteBuffer response;
 
+    /** Cache name. */
     private String cacheName;
 
+    /**
+     * Constructor.
+     *
+     * @param msgLen Length of the Redis message (command with parameters).
+     */
     public GridRedisMessage(int msgLen) {
         msgParts = new ArrayList<>(msgLen);
     }
@@ -67,19 +78,41 @@ public class GridRedisMessage implements GridClientMessage {
         msgParts.add(part);
     }
 
+    /**
+     * Sets the response.
+     *
+     * @param response Response.
+     */
     public void setResponse(ByteBuffer response) {
         this.response = response;
     }
 
+    /**
+     * Gets the response.
+     *
+     * @return Response.
+     */
     public ByteBuffer getResponse() {
         return response;
     }
 
-    public List<String> getMsgParts() {
+    /**
+     * Gets all message parts.
+     *
+     * @return Message elements.
+     */
+    private List<String> getMsgParts() {
         return msgParts;
     }
 
     /**
+     * @return Number of elements in the message.
+     */
+    public int messageSize() {
+        return msgParts.size();
+    }
+
+    /**
      * @return {@link GridRedisCommand}.
      */
     public GridRedisCommand command() {
@@ -96,6 +129,36 @@ public class GridRedisMessage implements GridClientMessage {
         return msgParts.get(KEY_POS);
     }
 
+    /**
+     * @return Parameters by index if available.
+     */
+    public String aux(int idx) {
+        if (msgParts.size() <= idx)
+            return null;
+
+        return msgParts.get(idx);
+    }
+
+    /**
+     * @return All parameters if available.
+     */
+    public List<String> aux() {
+        if (msgParts.size() <= AUX_OFFSET)
+            return null;
+
+        return msgParts.subList(AUX_OFFSET, msgParts.size());
+    }
+
+    /**
+     * @return All parameters for multi-key commands if available.
+     */
+    public List<String> auxMKeys() {
+        if (msgParts.size() <= KEY_POS)
+            return null;
+
+        return msgParts.subList(KEY_POS, msgParts.size());
+    }
+
     @Override public String toString() {
         return "GridRedisMessage [msg: " + msgParts + "]";
     }
@@ -155,11 +218,4 @@ public class GridRedisMessage implements GridClientMessage {
     @Override public void sessionToken(byte[] sesTok) {
 
     }
-
-    /**
-     * @return {@link RestQueryRequest}.
-     */
-    private RestQueryRequest asRestRequest() {
-        return null;
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
index 78dcb93..6bdb2c1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/GridRedisNioListener.java
@@ -28,11 +28,13 @@ import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.Gr
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisConnectionCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisAppendCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisGetCommandHandler;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisGetRangeCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisGetSetCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisIncrDecrCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisMGetCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisMSetCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisSetRangeCommandHandler;
 import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string.GridRedisStrlenCommandHandler;
 import org.apache.ignite.internal.util.nio.GridNioFuture;
 import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter;
@@ -70,6 +72,8 @@ public class GridRedisNioListener extends GridNioServerListenerAdapter<GridRedis
         addCommandHandler(new GridRedisAppendCommandHandler(ctx, hnd));
         addCommandHandler(new GridRedisGetSetCommandHandler(ctx, hnd));
         addCommandHandler(new GridRedisStrlenCommandHandler(ctx, hnd));
+        addCommandHandler(new GridRedisSetRangeCommandHandler(ctx, hnd));
+        addCommandHandler(new GridRedisGetRangeCommandHandler(ctx, hnd));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisStringCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisStringCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisStringCommandHandler.java
index c07656d..86dc6c5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisStringCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisStringCommandHandler.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
@@ -35,11 +36,12 @@ import org.apache.ignite.internal.util.typedef.CX1;
  */
 public abstract class GridRedisStringCommandHandler implements GridRedisCommandHandler {
     /** REST protocol handler. */
-    protected GridRestProtocolHandler hnd;
+    protected final GridRestProtocolHandler hnd;
 
     /**
      * Constructor.
      *
+     * @param ctx Context.
      * @param hnd REST protocol handler.
      */
     public GridRedisStringCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler
hnd) {
@@ -47,7 +49,7 @@ public abstract class GridRedisStringCommandHandler implements GridRedisCommandH
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage
msg) {
+    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(final GridRedisMessage
msg) {
         assert msg != null;
 
         try {
@@ -58,14 +60,12 @@ public abstract class GridRedisStringCommandHandler implements GridRedisCommandH
                         throws IgniteCheckedException {
                         GridRestResponse restRes = f.get();
 
-                        GridRedisMessage res = msg;
-
                         if (restRes.getSuccessStatus() == GridRestResponse.STATUS_SUCCESS)
-                            res.setResponse(makeResponse(restRes));
+                            msg.setResponse(makeResponse(restRes, msg.aux()));
                         else
-                            res.setResponse(GridRedisProtocolParser.toGenericError("Operation
error!"));
+                            msg.setResponse(GridRedisProtocolParser.toGenericError("Operation
error!"));
 
-                        return res;
+                        return msg;
                     }
                 });
         }
@@ -92,7 +92,8 @@ public abstract class GridRedisStringCommandHandler implements GridRedisCommandH
      * Prepares a response according to the request.
      *
      * @param resp REST response.
+     * @param params Auxiliary parameters.
      * @return
      */
-    public abstract ByteBuffer makeResponse(GridRestResponse resp);
+    public abstract ByteBuffer makeResponse(GridRestResponse resp, List<String> params);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
index be965f9..1e3b28a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisAppendCommandHandler.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.s
 
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
@@ -46,6 +47,7 @@ public class GridRedisAppendCommandHandler extends GridRedisStringCommandHandler
         APPEND
     );
 
+    /** Position of the value. */
     private static final int VAL_POS = 2;
 
     /** {@inheritDoc} */
@@ -62,13 +64,13 @@ public class GridRedisAppendCommandHandler extends GridRedisStringCommandHandler
     @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException
{
         assert msg != null;
 
-        if (msg.getMsgParts().size() < VAL_POS + 1)
+        if (msg.messageSize() < 3)
             throw new GridRedisGenericException("Wrong syntax!");
 
         GridRestCacheRequest appendReq = new GridRestCacheRequest();
         GridRestCacheRequest getReq = new GridRestCacheRequest();
 
-        String val = msg.getMsgParts().get(VAL_POS);
+        String val = msg.aux(VAL_POS);
 
         appendReq.clientId(msg.clientId());
         appendReq.key(msg.key());
@@ -95,7 +97,7 @@ public class GridRedisAppendCommandHandler extends GridRedisStringCommandHandler
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.nil();
         else {

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
index d9ce2f7..288f1e8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetCommandHandler.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.s
 
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
@@ -68,7 +69,7 @@ public class GridRedisGetCommandHandler extends GridRedisStringCommandHandler
{
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
             : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
new file mode 100644
index 0000000..4fc5c39
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetRangeCommandHandler.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisStringCommandHandler;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETRANGE;
+
+/**
+ * Redis SETRANGE command handler.
+ */
+public class GridRedisGetRangeCommandHandler extends GridRedisStringCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        GETRANGE
+    );
+
+    /** Start offset position in Redis message parameters. */
+    private static final int START_OFFSET_POS = 0;
+
+    /** End offset position in Redis message parameters. */
+    private static final int END_OFFSET_POS = 1;
+
+    /** {@inheritDoc} */
+    public GridRedisGetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler
hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException
{
+        assert msg != null;
+
+        if (msg.messageSize() < 4)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        return getReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toBulkString("");
+        else {
+            String res = String.valueOf(restRes.getResponse());
+            int startOffset;
+            int endOffset;
+
+            try {
+                startOffset = boundedStartOffset(Integer.parseInt(params.get(START_OFFSET_POS)),
res.length());
+                endOffset = boundedEndOffset(Integer.parseInt(params.get(END_OFFSET_POS)),
res.length());
+            }
+            catch (NumberFormatException e) {
+                return GridRedisProtocolParser.toGenericError("Offset is not an integer!");
+            }
+
+            return GridRedisProtocolParser.toBulkString(res.substring(startOffset, endOffset));
+        }
+    }
+
+    /**
+     * @param idx Index.
+     * @param size Bounds.
+     * @return Offset within the bounds.
+     */
+    private int boundedStartOffset(int idx, int size) {
+        if (idx >= 0)
+            return Math.min(idx, size);
+        else
+            return size + idx;
+    }
+
+    /**
+     * @param idx Index.
+     * @param size Bounds.
+     * @return Offset within the bounds.
+     */
+    private int boundedEndOffset(int idx, int size) {
+        if (idx >= 0)
+            return Math.min(idx + 1, size);
+        else
+            return size + idx + 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
index 7ef55fb..8ba15d0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisGetSetCommandHandler.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.s
 
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
@@ -61,14 +62,14 @@ public class GridRedisGetSetCommandHandler extends GridRedisStringCommandHandler
     @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException
{
         assert msg != null;
 
-        if (msg.getMsgParts().size() < VAL_POS + 1)
+        if (msg.messageSize() < 3)
             throw new GridRedisGenericException("Wrong syntax!");
 
         GridRestCacheRequest restReq = new GridRestCacheRequest();
 
         restReq.clientId(msg.clientId());
         restReq.key(msg.key());
-        restReq.value(msg.getMsgParts().get(VAL_POS));
+        restReq.value(msg.aux(VAL_POS));
 
         restReq.command(CACHE_GET_AND_PUT);
 
@@ -76,7 +77,7 @@ public class GridRedisGetSetCommandHandler extends GridRedisStringCommandHandler
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
             : GridRedisProtocolParser.toBulkString(restRes.getResponse()));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
index 78e042c..58575f0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisIncrDecrCommandHandler.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.s
 import java.math.BigDecimal;
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
@@ -54,6 +55,7 @@ public class GridRedisIncrDecrCommandHandler extends GridRedisStringCommandHandl
         DECRBY
     );
 
+    /** Delta position in the message. */
     private static final int DELTA_POS = 2;
 
     /** {@inheritDoc} */
@@ -94,9 +96,9 @@ public class GridRedisIncrDecrCommandHandler extends GridRedisStringCommandHandl
         restReq.key(msg.key());
         restReq.delta(1L);
 
-        if (msg.getMsgParts().size() > DELTA_POS) {
+        if (msg.messageSize() > 2) {
             try {
-                restReq.delta(Long.valueOf(msg.getMsgParts().get(DELTA_POS)));
+                restReq.delta(Long.valueOf(msg.aux(DELTA_POS)));
             }
             catch (NumberFormatException e) {
                 throw new GridRedisGenericException("An increment value must be numeric and
in range!");
@@ -119,7 +121,7 @@ public class GridRedisIncrDecrCommandHandler extends GridRedisStringCommandHandl
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.toGenericError("Failed to increment!");
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
index 4a73a48..3f6bfc3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMGetCommandHandler.java
@@ -67,7 +67,7 @@ public class GridRedisMGetCommandHandler extends GridRedisStringCommandHandler
{
 
         restReq.command(CACHE_GET_ALL);
 
-        List<String> keys = msg.getMsgParts().subList(1, msg.getMsgParts().size());
+        List<String> keys = msg.auxMKeys();
         Map<Object, Object> mget = U.newHashMap(keys.size());
         Iterator<String> mgetIt = keys.iterator();
 
@@ -80,7 +80,7 @@ public class GridRedisMGetCommandHandler extends GridRedisStringCommandHandler
{
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
             : GridRedisProtocolParser.toArray((Map<Object, Object>)restRes.getResponse()));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
index 409be4e..af896f7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisMSetCommandHandler.java
@@ -67,7 +67,7 @@ public class GridRedisMSetCommandHandler extends GridRedisStringCommandHandler
{
 
         restReq.command(CACHE_PUT_ALL);
 
-        List<String> els = msg.getMsgParts().subList(1, msg.getMsgParts().size());
+        List<String> els = msg.auxMKeys();
         Map<Object, Object> mset = U.newHashMap(els.size() / 2);
         Iterator<String> msetIt = els.iterator();
 
@@ -80,7 +80,7 @@ public class GridRedisMSetCommandHandler extends GridRedisStringCommandHandler
{
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         return GridRedisProtocolParser.OkString();
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
index 2737c4d..d1b6c70 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetCommandHandler.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.s
 
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
@@ -36,6 +37,8 @@ import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.Gri
 
 /**
  * Redis SET command handler.
+ * <p>
+ * No key expiration is currently supported.
  */
 public class GridRedisSetCommandHandler extends GridRedisStringCommandHandler {
     /** Supported commands. */
@@ -43,6 +46,9 @@ public class GridRedisSetCommandHandler extends GridRedisStringCommandHandler
{
         SET
     );
 
+    /** Value position in Redis message. */
+    private static final int VAL_POS = 2;
+
     /** {@inheritDoc} */
     public GridRedisSetCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler
hnd) {
         super(ctx, hnd);
@@ -64,12 +70,12 @@ public class GridRedisSetCommandHandler extends GridRedisStringCommandHandler
{
 
         restReq.command(CACHE_PUT);
 
-        if (msg.getMsgParts().size() < 3)
+        if (msg.messageSize() < 3)
             throw new IgniteCheckedException("Invalid request!");
 
-        restReq.value(msg.getMsgParts().get(2));
+        restReq.value(msg.aux(VAL_POS));
 
-        if (msg.getMsgParts().size() >= 4) {
+        if (msg.messageSize() >= 4) {
             // handle options.
         }
 
@@ -77,7 +83,7 @@ public class GridRedisSetCommandHandler extends GridRedisStringCommandHandler
{
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         return (restRes.getResponse() == null ? GridRedisProtocolParser.nil()
             : GridRedisProtocolParser.OkString());
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
new file mode 100644
index 0000000..c9cc3d2
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisSetRangeCommandHandler.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisStringCommandHandler;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SETRANGE;
+
+/**
+ * Redis SETRANGE command handler.
+ */
+public class GridRedisSetRangeCommandHandler extends GridRedisStringCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        SETRANGE
+    );
+
+    /** Offset position in Redis message among parameters. */
+    private static final int OFFSET_POS = 2;
+
+    /** Value position in Redis message. */
+    private static final int VAL_POS = 3;
+
+    /** {@inheritDoc} */
+    public GridRedisSetRangeCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler
hnd) {
+        super(ctx, hnd);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException
{
+        assert msg != null;
+
+        if (msg.messageSize() < 4)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        int offset;
+        try {
+            offset = Integer.parseInt(msg.aux(OFFSET_POS));
+        }
+        catch (NumberFormatException e) {
+            throw new GridRedisGenericException("Offset is not an integer!");
+        }
+
+        String val = String.valueOf(msg.aux(VAL_POS));
+
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        if (val.length() == 0)
+            return getReq;
+
+        Object resp = hnd.handle(getReq).getResponse();
+
+        int totalLen = offset + val.length();
+        if (offset < 0 || totalLen > 536870911)
+            throw new GridRedisGenericException("Offset is out of range!");
+
+        GridRestCacheRequest putReq = new GridRestCacheRequest();
+
+        putReq.clientId(msg.clientId());
+        putReq.key(msg.key());
+        putReq.command(CACHE_PUT);
+
+        if (resp == null) {
+            byte[] dst = new byte[totalLen];
+            System.arraycopy(val.getBytes(), 0, dst, offset, val.length());
+
+            putReq.value(new String(dst));
+        }
+        else {
+            String cacheVal = String.valueOf(resp);
+
+            cacheVal = cacheVal.substring(0, offset) + val;
+
+            putReq.value(cacheVal);
+        }
+
+        hnd.handle(putReq);
+
+        return getReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toInteger("0");
+        else {
+            int resLen = ((String)restRes.getResponse()).length();
+            return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/62d5cafe/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
index d62ddae..3d480e6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/string/GridRedisStrlenCommandHandler.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.s
 
 import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
@@ -68,7 +69,7 @@ public class GridRedisStrlenCommandHandler extends GridRedisStringCommandHandler
     }
 
     /** {@inheritDoc} */
-    @Override public ByteBuffer makeResponse(final GridRestResponse restRes) {
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String>
params) {
         if (restRes.getResponse() == null)
             return GridRedisProtocolParser.toInteger("0");
         else {


Mime
View raw message