Repository: fppt/jedis-mock (java)

Issue:
In case of RENAME delete the target key if already present
The current implementation of rename, doesn't delete the values from target key. 
This will merge the map result in case of HMAP.   
The target key should be delete before renaming 

Here is an extract from the [doc](https://redis.io/commands/rename)
>  If newkey already exists it is overwritten, when this happens RENAME executes an implicit DEL operation

Pull request description:
Fix #84 Delete target key before rename
Hi,

Here is a patch deleting the key before renaming.

/Benoît

Patch:
diff --git a/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java b/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
index 4792732..42890f7 100644
--- a/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
+++ b/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
@@ -89,6 +89,7 @@ public class OperationFactory {
         TRANSACTIONAL_OPERATIONS.put("zrange", RO_zrange::new);
         TRANSACTIONAL_OPERATIONS.put("zrangebylex", RO_zrangebylex::new);
         TRANSACTIONAL_OPERATIONS.put("zrem", RO_zrem::new);
+        TRANSACTIONAL_OPERATIONS.put("client", RO_client::new);
         TRANSACTIONAL_OPERATIONS.put("rename", RO_rename::new);
     }
 
diff --git a/src/main/java/com/github/fppt/jedismock/operations/RO_client.java b/src/main/java/com/github/fppt/jedismock/operations/RO_client.java
new file mode 100644
index 0000000..76dfa2f
--- /dev/null
+++ b/src/main/java/com/github/fppt/jedismock/operations/RO_client.java
@@ -0,0 +1,18 @@
+package com.github.fppt.jedismock.operations;
+
+import com.github.fppt.jedismock.server.Response;
+import com.github.fppt.jedismock.server.Slice;
+import com.github.fppt.jedismock.storage.RedisBase;
+
+import java.util.List;
+
+class RO_client extends AbstractRedisOperation {
+  RO_client(RedisBase base, List<Slice> params) {
+      super(base, params);
+  }
+
+  Slice response() {
+      Slice key = params().get(1);
+      return Response.bulkString(key);
+  }
+}
diff --git a/src/main/java/com/github/fppt/jedismock/operations/RO_rename.java b/src/main/java/com/github/fppt/jedismock/operations/RO_rename.java
index 1de3362..ec0bda9 100644
--- a/src/main/java/com/github/fppt/jedismock/operations/RO_rename.java
+++ b/src/main/java/com/github/fppt/jedismock/operations/RO_rename.java
@@ -19,6 +19,8 @@ class RO_rename extends AbstractRedisOperation {
         if (ttl == null) {
             return false;
         }
+
+        base().deleteValue(newKey);
         for (Map.Entry<Slice, Slice> entry : value.entrySet()) {
             base().putValue(newKey, entry.getKey(), entry.getValue(), ttl);
         }


Test patch:
diff --git a/src/test/java/com/github/fppt/jedismock/TestRedisOperationExecutor.java b/src/test/java/com/github/fppt/jedismock/TestRedisOperationExecutor.java
index 0bde873..ce43c0e 100644
--- a/src/test/java/com/github/fppt/jedismock/TestRedisOperationExecutor.java
+++ b/src/test/java/com/github/fppt/jedismock/TestRedisOperationExecutor.java
@@ -440,4 +440,14 @@ public class TestRedisOperationExecutor {
         assertCommandNull(array("get", "old"));
     }
 
+    @Test
+    public void testRenameHashWithExistingValues() {
+        assertCommandEquals(1, array("hset", "old", "a", "1"));
+        assertCommandEquals(1, array("hset", "new", "z", "2"));
+        assertCommandOK(array("rename", "old", "new"));
+        assertCommandEquals("1", array("hget", "new", "a"));
+        assertCommandNull(array("hget", "new", "z"));
+        assertCommandNull(array("get", "old"));
+    }
+
 }
diff --git a/src/test/java/com/github/fppt/jedismock/TestRedisServer.java b/src/test/java/com/github/fppt/jedismock/TestRedisServer.java
index 1c32421..839a5bf 100644
--- a/src/test/java/com/github/fppt/jedismock/TestRedisServer.java
+++ b/src/test/java/com/github/fppt/jedismock/TestRedisServer.java
@@ -72,6 +72,16 @@ public class TestRedisServer {
         }
     }
 
+    @Test
+    public void testSetClientName() throws IOException {
+      RedisServer server = RedisServer.newRedisServer();
+      server.start();
+
+      Jedis jedis = new Jedis(server.getHost(), server.getBindPort());
+      String clientName = "Test Client Name";
+      assertEquals(clientName, jedis.clientSetname("Test Client Name"));
+    }
+
     @Test
     public void whenRepeatedlyStoppingAndStartingServer_EnsureItResponds() throws IOException {
         for (int i = 0; i < 20; i ++){