ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shro...@apache.org
Subject [2/2] ignite git commit: IGNITE-2788: Moved handlers.
Date Tue, 01 Nov 2016 03:08:52 GMT
IGNITE-2788: Moved handlers.


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

Branch: refs/heads/ignite-2788
Commit: a8dae9d0090b53d9a409fb2985fe15ed76319a57
Parents: 127f459
Author: shtykh_roman <rshtykh@yahoo.com>
Authored: Tue Nov 1 12:07:18 2016 +0900
Committer: shtykh_roman <rshtykh@yahoo.com>
Committed: Tue Nov 1 12:07:18 2016 +0900

----------------------------------------------------------------------
 modules/clients/pom.xml                         |   2 +-
 .../handlers/redis/GridRedisCommandHandler.java |  39 ++++++
 .../GridRedisConnectionCommandHandler.java      |  71 ++++++++++
 .../redis/GridRedisThruRestCommandHandler.java  |  99 ++++++++++++++
 .../exception/GridRedisGenericException.java    |  20 +++
 .../redis/exception/GridRedisTypeException.java |  20 +++
 .../redis/key/GridRedisDelCommandHandler.java   |  91 +++++++++++++
 .../key/GridRedisExistsCommandHandler.java      |  90 +++++++++++++
 .../server/GridRedisDbSizeCommandHandler.java   |  75 +++++++++++
 .../string/GridRedisAppendCommandHandler.java   | 108 +++++++++++++++
 .../string/GridRedisGetCommandHandler.java      |  76 +++++++++++
 .../string/GridRedisGetRangeCommandHandler.java | 124 +++++++++++++++++
 .../string/GridRedisGetSetCommandHandler.java   |  84 ++++++++++++
 .../string/GridRedisIncrDecrCommandHandler.java | 133 +++++++++++++++++++
 .../string/GridRedisMGetCommandHandler.java     |  90 +++++++++++++
 .../string/GridRedisMSetCommandHandler.java     |  86 ++++++++++++
 .../string/GridRedisSetCommandHandler.java      |  90 +++++++++++++
 .../string/GridRedisSetRangeCommandHandler.java | 131 ++++++++++++++++++
 .../string/GridRedisStrlenCommandHandler.java   |  80 +++++++++++
 .../tcp/redis/GridRedisNioListener.java         |  31 +++--
 .../redis/handler/GridRedisCommandHandler.java  |  39 ------
 .../GridRedisConnectionCommandHandler.java      |  71 ----------
 .../GridRedisThruRestCommandHandler.java        |  99 --------------
 .../exception/GridRedisGenericException.java    |  20 ---
 .../exception/GridRedisTypeException.java       |  20 ---
 .../handler/key/GridRedisDelCommandHandler.java |  91 -------------
 .../key/GridRedisExistsCommandHandler.java      |  90 -------------
 .../server/GridRedisDbSizeCommandHandler.java   |  75 -----------
 .../string/GridRedisAppendCommandHandler.java   | 108 ---------------
 .../string/GridRedisGetCommandHandler.java      |  76 -----------
 .../string/GridRedisGetRangeCommandHandler.java | 124 -----------------
 .../string/GridRedisGetSetCommandHandler.java   |  84 ------------
 .../string/GridRedisIncrDecrCommandHandler.java | 133 -------------------
 .../string/GridRedisMGetCommandHandler.java     |  90 -------------
 .../string/GridRedisMSetCommandHandler.java     |  86 ------------
 .../string/GridRedisSetCommandHandler.java      |  90 -------------
 .../string/GridRedisSetRangeCommandHandler.java | 131 ------------------
 .../string/GridRedisStrlenCommandHandler.java   |  80 -----------
 38 files changed, 1523 insertions(+), 1524 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/clients/pom.xml
----------------------------------------------------------------------
diff --git a/modules/clients/pom.xml b/modules/clients/pom.xml
index 729bc89..88eed4d 100644
--- a/modules/clients/pom.xml
+++ b/modules/clients/pom.xml
@@ -58,7 +58,7 @@
         <dependency>
             <groupId>redis.clients</groupId>
             <artifactId>jedis</artifactId>
-            <version>2.8.1</version>
+            <version>2.9.0</version>
         </dependency>
 
         <dependency>

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java
new file mode 100644
index 0000000..16c3f3e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisCommandHandler.java
@@ -0,0 +1,39 @@
+/*
+ * 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.handlers.redis;
+
+import java.util.Collection;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
+
+/**
+ * Command handler.
+ */
+public interface GridRedisCommandHandler {
+    /**
+     * @return Collection of supported commands.
+     */
+    Collection<GridRedisCommand> supportedCommands();
+
+    /**
+     * @param msg Request message.
+     * @return Future.
+     */
+    IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java
new file mode 100644
index 0000000..a5993c1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisConnectionCommandHandler.java
@@ -0,0 +1,71 @@
+/*
+ * 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.handlers.redis;
+
+import java.util.Collection;
+import org.apache.ignite.internal.IgniteInternalFuture;
+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.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.ECHO;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.PING;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.QUIT;
+
+/**
+ * Redis connection handler.
+ */
+public class GridRedisConnectionCommandHandler implements GridRedisCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        PING,
+        QUIT,
+        ECHO
+    );
+
+    /** PONG response to PING. */
+    private static final String PONG = "PONG";
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg) {
+        assert msg != null;
+
+        switch (msg.command()) {
+            case PING:
+                msg.setResponse(GridRedisProtocolParser.toSimpleString(PONG));
+                return new GridFinishedFuture<>(msg);
+
+            case QUIT:
+                msg.setResponse(GridRedisProtocolParser.OkString());
+                return new GridFinishedFuture<>(msg);
+
+            case ECHO:
+                msg.setResponse(GridRedisProtocolParser.toSimpleString(msg.key()));
+                return new GridFinishedFuture<>(msg);
+        }
+
+        return new GridFinishedFuture<>();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java
new file mode 100644
index 0000000..73a4131
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/GridRedisThruRestCommandHandler.java
@@ -0,0 +1,99 @@
+/*
+ * 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.handlers.redis;
+
+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;
+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.GridRedisMessage;
+import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisProtocolParser;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisTypeException;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.typedef.CX1;
+
+/**
+ * Redis command handler done via REST.
+ */
+public abstract class GridRedisThruRestCommandHandler implements GridRedisCommandHandler {
+    /** REST protocol handler. */
+    protected final GridRestProtocolHandler hnd;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param hnd REST protocol handler.
+     */
+    public GridRedisThruRestCommandHandler(final GridKernalContext ctx, final GridRestProtocolHandler hnd) {
+        this.hnd = hnd;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(final GridRedisMessage msg) {
+        assert msg != null;
+
+        try {
+            return hnd.handleAsync(asRestRequest(msg))
+                .chain(new CX1<IgniteInternalFuture<GridRestResponse>, GridRedisMessage>() {
+                    @Override
+                    public GridRedisMessage applyx(IgniteInternalFuture<GridRestResponse> f)
+                        throws IgniteCheckedException {
+                        GridRestResponse restRes = f.get();
+
+                        if (restRes.getSuccessStatus() == GridRestResponse.STATUS_SUCCESS)
+                            msg.setResponse(makeResponse(restRes, msg.auxMKeys()));
+                        else
+                            msg.setResponse(GridRedisProtocolParser.toGenericError("Operation error!"));
+
+                        return msg;
+                    }
+                });
+        }
+        catch (IgniteCheckedException e) {
+            if (e instanceof GridRedisTypeException)
+                msg.setResponse(GridRedisProtocolParser.toTypeError(e.getMessage()));
+            else
+                msg.setResponse(GridRedisProtocolParser.toGenericError(e.getMessage()));
+
+            return new GridFinishedFuture<>(msg);
+        }
+    }
+
+    /**
+     * Converts {@link GridRedisMessage} to {@link GridRestRequest}.
+     *
+     * @param msg {@link GridRedisMessage}
+     * @return {@link GridRestRequest}
+     * @throws IgniteCheckedException If fails.
+     */
+    public abstract GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException;
+
+    /**
+     * Prepares a response according to the request.
+     *
+     * @param resp REST response.
+     * @param params Auxiliary parameters.
+     * @return
+     */
+    public abstract ByteBuffer makeResponse(GridRestResponse resp, List<String> params);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java
new file mode 100644
index 0000000..2e457b6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisGenericException.java
@@ -0,0 +1,20 @@
+package org.apache.ignite.internal.processors.rest.handlers.redis.exception;
+
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Generic Redis protocol exception.
+ */
+public class GridRedisGenericException extends IgniteCheckedException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Creates a generic exception with given error message.
+     *
+     * @param msg Error message.
+     */
+    public GridRedisGenericException(String msg) {
+        super(msg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java
new file mode 100644
index 0000000..cf24b6d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/exception/GridRedisTypeException.java
@@ -0,0 +1,20 @@
+package org.apache.ignite.internal.processors.rest.handlers.redis.exception;
+
+import org.apache.ignite.IgniteCheckedException;
+
+/**
+ * Exception on operation on the wrong data type.
+ */
+public class GridRedisTypeException extends IgniteCheckedException {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /**
+     * Creates a type exception with given error message.
+     *
+     * @param msg Error message.
+     */
+    public GridRedisTypeException(String msg) {
+        super(msg);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java
new file mode 100644
index 0000000..62fa2b0
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisDelCommandHandler.java
@@ -0,0 +1,91 @@
+/*
+ * 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.handlers.redis.key;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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_REMOVE_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DEL;
+
+/**
+ * Redis DEL command handler.
+ */
+public class GridRedisDelCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        DEL
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisDelCommandHandler(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() < 2)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_REMOVE_ALL);
+
+        List<String> keys = msg.auxMKeys();
+        Map<Object, Object> mget = U.newHashMap(keys.size());
+        Iterator<String> mgetIt = keys.iterator();
+
+        while (mgetIt.hasNext())
+            mget.put(mgetIt.next(), null);
+
+        restReq.values(mget);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        // It has to respond with the number of removed entries...
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
+            : GridRedisProtocolParser.toInteger(String.valueOf(params.size())));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java
new file mode 100644
index 0000000..3802517
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/key/GridRedisExistsCommandHandler.java
@@ -0,0 +1,90 @@
+/*
+ * 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.handlers.redis.key;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.EXISTS;
+
+/**
+ * Redis EXISTS command handler.
+ */
+public class GridRedisExistsCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        EXISTS
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisExistsCommandHandler(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() < 2)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_GET_ALL);
+
+        List<String> keys = msg.auxMKeys();
+        Map<Object, Object> mget = U.newHashMap(keys.size());
+        Iterator<String> mgetIt = keys.iterator();
+
+        while (mgetIt.hasNext())
+            mget.put(mgetIt.next(), null);
+
+        restReq.values(mget);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
+            : GridRedisProtocolParser.toInteger(((Map<Object, Object>)restRes.getResponse()).size()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java
new file mode 100644
index 0000000..27daad4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/server/GridRedisDbSizeCommandHandler.java
@@ -0,0 +1,75 @@
+/*
+ * 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.handlers.redis.server;
+
+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.handlers.redis.GridRedisThruRestCommandHandler;
+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_SIZE;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DBSIZE;
+
+/**
+ * Redis DBSIZE command handler.
+ */
+public class GridRedisDbSizeCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        DBSIZE
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisDbSizeCommandHandler(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;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_SIZE);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return (restRes.getResponse() == null ? GridRedisProtocolParser.toInteger("0")
+            : GridRedisProtocolParser.toInteger(String.valueOf(restRes.getResponse())));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
new file mode 100644
index 0000000..331f7fe
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisAppendCommandHandler.java
@@ -0,0 +1,108 @@
+/*
+ * 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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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_APPEND;
+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.APPEND;
+
+/**
+ * Redis APPEND command handler.
+ */
+public class GridRedisAppendCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        APPEND
+    );
+
+    /** Position of the value. */
+    private static final int VAL_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisAppendCommandHandler(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() < 3)
+            throw new GridRedisGenericException("Wrong syntax!");
+
+        GridRestCacheRequest appendReq = new GridRestCacheRequest();
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        String val = msg.aux(VAL_POS);
+
+        appendReq.clientId(msg.clientId());
+        appendReq.key(msg.key());
+        appendReq.value(val);
+        appendReq.command(CACHE_APPEND);
+
+        if ((boolean)hnd.handle(appendReq).getResponse() == false) {
+            // append on on-existing key in REST returns false.
+            GridRestCacheRequest setReq = new GridRestCacheRequest();
+
+            setReq.clientId(msg.clientId());
+            setReq.key(msg.key());
+            setReq.value(val);
+            setReq.command(CACHE_PUT);
+
+            hnd.handle(setReq);
+        }
+
+        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.nil();
+        else {
+            int resLen = ((String)restRes.getResponse()).length();
+            return GridRedisProtocolParser.toInteger(String.valueOf(resLen));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
new file mode 100644
index 0000000..b06e411
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetCommandHandler.java
@@ -0,0 +1,76 @@
+/*
+ * 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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+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.GET;
+
+/**
+ * Redis GET command handler.
+ */
+public class GridRedisGetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        GET
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisGetCommandHandler(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;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_GET);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @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/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetRangeCommandHandler.java
new file mode 100644
index 0000000..481e07a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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 GridRedisThruRestCommandHandler {
+    /** 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 = 1;
+
+    /** End offset position in Redis message parameters. */
+    private static final int END_OFFSET_POS = 2;
+
+    /** {@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/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
new file mode 100644
index 0000000..0f302e5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisGetSetCommandHandler.java
@@ -0,0 +1,84 @@
+/*
+ * 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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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_AND_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.GETSET;
+
+/**
+ * Redis GETSET command handler.
+ */
+public class GridRedisGetSetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        GETSET
+    );
+
+    /** Value position in Redis message. */
+    private static final int VAL_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisGetSetCommandHandler(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() < 3)
+            throw new GridRedisGenericException("Wrong syntax!");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.value(msg.aux(VAL_POS));
+
+        restReq.command(CACHE_GET_AND_PUT);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @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/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java
new file mode 100644
index 0000000..34d4b31
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisIncrDecrCommandHandler.java
@@ -0,0 +1,133 @@
+/*
+ * 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.handlers.redis.string;
+
+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;
+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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.exception.GridRedisGenericException;
+import org.apache.ignite.internal.processors.rest.request.DataStructuresRequest;
+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.ATOMIC_DECREMENT;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.ATOMIC_INCREMENT;
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECR;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.DECRBY;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCR;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.INCRBY;
+
+/**
+ * Redis INCR/DECR command handler.
+ */
+public class GridRedisIncrDecrCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        INCR,
+        DECR,
+        INCRBY,
+        DECRBY
+    );
+
+    /** Delta position in the message. */
+    private static final int DELTA_POS = 2;
+
+    /** {@inheritDoc} */
+    public GridRedisIncrDecrCommandHandler(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;
+
+        DataStructuresRequest restReq = new DataStructuresRequest();
+
+        GridRestCacheRequest getReq = new GridRestCacheRequest();
+
+        getReq.clientId(msg.clientId());
+        getReq.key(msg.key());
+        getReq.command(CACHE_GET);
+
+        GridRestResponse getResp = hnd.handle(getReq);
+
+        if (getResp.getResponse() == null) {
+            restReq.initial(0L);
+        }
+        else {
+            if (getResp.getResponse() instanceof Long && (Long)getResp.getResponse() <= Long.MAX_VALUE)
+                restReq.initial((Long)getResp.getResponse());
+            else
+                throw new GridRedisGenericException("An initial value must be numeric and in range!");
+        }
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.delta(1L);
+
+        if (msg.messageSize() > 2) {
+            try {
+                restReq.delta(Long.valueOf(msg.aux(DELTA_POS)));
+            }
+            catch (NumberFormatException e) {
+                throw new GridRedisGenericException("An increment value must be numeric and in range!");
+            }
+        }
+
+        switch (msg.command()) {
+            case INCR:
+            case INCRBY:
+                restReq.command(ATOMIC_INCREMENT);
+                break;
+
+            case DECR:
+            case DECRBY:
+                restReq.command(ATOMIC_DECREMENT);
+                break;
+        }
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toGenericError("Failed to increment!");
+
+        if (restRes.getResponse() instanceof Long && (Long)restRes.getResponse() <= Long.MAX_VALUE)
+            return GridRedisProtocolParser.toInteger(new BigDecimal((Long)restRes.getResponse()).toString());
+        else
+            return GridRedisProtocolParser.toTypeError("Value is non-numeric or out of range!");
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java
new file mode 100644
index 0000000..4cf8345
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMGetCommandHandler.java
@@ -0,0 +1,90 @@
+/*
+ * 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.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MGET;
+
+/**
+ * Redis MGET command handler.
+ */
+public class GridRedisMGetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        MGET
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisMGetCommandHandler(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() < 2)
+            throw new GridRedisGenericException("Wrong number of arguments");
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+        restReq.command(CACHE_GET_ALL);
+
+        List<String> keys = msg.auxMKeys();
+        Map<Object, Object> mget = U.newHashMap(keys.size());
+        Iterator<String> mgetIt = keys.iterator();
+
+        while (mgetIt.hasNext())
+            mget.put(mgetIt.next(), null);
+
+        restReq.values(mget);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @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/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java
new file mode 100644
index 0000000..783fed5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisMSetCommandHandler.java
@@ -0,0 +1,86 @@
+/*
+ * 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.handlers.redis.string;
+
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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.handlers.redis.GridRedisThruRestCommandHandler;
+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_PUT_ALL;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.MSET;
+
+/**
+ * Redis MSET command handler.
+ */
+public class GridRedisMSetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        MSET
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisMSetCommandHandler(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;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_PUT_ALL);
+
+        List<String> els = msg.auxMKeys();
+        Map<Object, Object> mset = U.newHashMap(els.size() / 2);
+        Iterator<String> msetIt = els.iterator();
+
+        while (msetIt.hasNext())
+            mset.put(msetIt.next(), msetIt.hasNext() ? msetIt.next() : null);
+
+        restReq.values(mset);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        return GridRedisProtocolParser.OkString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java
new file mode 100644
index 0000000..09b97ab
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetCommandHandler.java
@@ -0,0 +1,90 @@
+/*
+ * 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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+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_PUT;
+import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.SET;
+
+/**
+ * Redis SET command handler.
+ * <p>
+ * No key expiration is currently supported.
+ */
+public class GridRedisSetCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        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);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRedisCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridRestRequest asRestRequest(GridRedisMessage msg) throws IgniteCheckedException {
+        assert msg != null;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_PUT);
+
+        if (msg.messageSize() < 3)
+            throw new IgniteCheckedException("Invalid request!");
+
+        restReq.value(msg.aux(VAL_POS));
+
+        if (msg.messageSize() >= 4) {
+            // handle options.
+        }
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @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/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisSetRangeCommandHandler.java
new file mode 100644
index 0000000..0063c66
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.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 GridRedisThruRestCommandHandler {
+    /** 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/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
new file mode 100644
index 0000000..441bf42
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/redis/string/GridRedisStrlenCommandHandler.java
@@ -0,0 +1,80 @@
+/*
+ * 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.handlers.redis.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.handlers.redis.GridRedisThruRestCommandHandler;
+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.STRLEN;
+
+/**
+ * Redis STRLEN command handler.
+ */
+public class GridRedisStrlenCommandHandler extends GridRedisThruRestCommandHandler {
+    /** Supported commands. */
+    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
+        STRLEN
+    );
+
+    /** {@inheritDoc} */
+    public GridRedisStrlenCommandHandler(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;
+
+        GridRestCacheRequest restReq = new GridRestCacheRequest();
+
+        restReq.clientId(msg.clientId());
+        restReq.key(msg.key());
+
+        restReq.command(CACHE_GET);
+
+        return restReq;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ByteBuffer makeResponse(final GridRestResponse restRes, List<String> params) {
+        if (restRes.getResponse() == null)
+            return GridRedisProtocolParser.toInteger("0");
+        else {
+            int len = String.valueOf(restRes.getResponse()).length();
+            return GridRedisProtocolParser.toInteger(String.valueOf(len));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/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 555787b..1ff4a4a 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
@@ -24,22 +24,21 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.rest.GridRestProtocolHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.GridRedisConnectionCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key.GridRedisDelCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.key.GridRedisExistsCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.server.GridRedisDbSizeCommandHandler;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.handler.server.GridRedisFlushDbCommandHandler;
-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.processors.rest.handlers.redis.GridRedisCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.GridRedisConnectionCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.key.GridRedisDelCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.key.GridRedisExistsCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.server.GridRedisDbSizeCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisAppendCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisGetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisGetRangeCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisGetSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisIncrDecrCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisMGetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisMSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisSetCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisSetRangeCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.redis.string.GridRedisStrlenCommandHandler;
 import org.apache.ignite.internal.util.nio.GridNioFuture;
 import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter;
 import org.apache.ignite.internal.util.nio.GridNioSession;

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java
deleted file mode 100644
index a1f292d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisCommandHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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;
-
-import java.util.Collection;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand;
-import org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisMessage;
-
-/**
- * Command handler.
- */
-public interface GridRedisCommandHandler {
-    /**
-     * @return Collection of supported commands.
-     */
-    Collection<GridRedisCommand> supportedCommands();
-
-    /**
-     * @param msg Request message.
-     * @return Future.
-     */
-    IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8dae9d0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java
deleted file mode 100644
index 6dcaecb..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/redis/handler/GridRedisConnectionCommandHandler.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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;
-
-import java.util.Collection;
-import org.apache.ignite.internal.IgniteInternalFuture;
-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.util.future.GridFinishedFuture;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.ECHO;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.PING;
-import static org.apache.ignite.internal.processors.rest.protocols.tcp.redis.GridRedisCommand.QUIT;
-
-/**
- * Redis connection handler.
- */
-public class GridRedisConnectionCommandHandler implements GridRedisCommandHandler {
-    /** Supported commands. */
-    private static final Collection<GridRedisCommand> SUPPORTED_COMMANDS = U.sealList(
-        PING,
-        QUIT,
-        ECHO
-    );
-
-    /** PONG response to PING. */
-    private static final String PONG = "PONG";
-
-    /** {@inheritDoc} */
-    @Override public Collection<GridRedisCommand> supportedCommands() {
-        return SUPPORTED_COMMANDS;
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<GridRedisMessage> handleAsync(GridRedisMessage msg) {
-        assert msg != null;
-
-        switch (msg.command()) {
-            case PING:
-                msg.setResponse(GridRedisProtocolParser.toSimpleString(PONG));
-                return new GridFinishedFuture<>(msg);
-
-            case QUIT:
-                msg.setResponse(GridRedisProtocolParser.OkString());
-                return new GridFinishedFuture<>(msg);
-
-            case ECHO:
-                msg.setResponse(GridRedisProtocolParser.toSimpleString(msg.key()));
-                return new GridFinishedFuture<>(msg);
-        }
-
-        return new GridFinishedFuture<>();
-    }
-}


Mime
View raw message