Repository: fppt/jedis-mock (java)

Issue:
Unsupported operation 'sismember'
The sismember operation is unsupported.

Pull request:
Fix #52: implement sismember
Fixed #52 

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 8bc5514..e56abed 100644
--- a/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
+++ b/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
@@ -65,6 +65,7 @@ public class OperationFactory {
         TRANSACTIONAL_OPERATIONS.put("spop", RO_spop::new);
         TRANSACTIONAL_OPERATIONS.put("srem", RO_srem::new);
         TRANSACTIONAL_OPERATIONS.put("scard", RO_scard::new);
+        TRANSACTIONAL_OPERATIONS.put("sismember", RO_sismember::new);
         TRANSACTIONAL_OPERATIONS.put("hexists", RO_hexists::new);
         TRANSACTIONAL_OPERATIONS.put("hget", RO_hget::new);
         TRANSACTIONAL_OPERATIONS.put("hset", RO_hset::new);
diff --git a/src/main/java/com/github/fppt/jedismock/operations/RO_sismember.java b/src/main/java/com/github/fppt/jedismock/operations/RO_sismember.java
new file mode 100644
index 0000000..23b6d69
--- /dev/null
+++ b/src/main/java/com/github/fppt/jedismock/operations/RO_sismember.java
@@ -0,0 +1,24 @@
+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;
+import java.util.Set;
+
+public class RO_sismember extends AbstractRedisOperation {
+
+    RO_sismember(RedisBase base, List<Slice> params) {
+        super(base, params);
+    }
+
+    @Override
+    Slice response() {
+        Slice key = params().get(0);
+        Slice member = params().get(1);
+        Set<Slice> set = getDataFromBase(key, null);
+        if (set == null || set.isEmpty()) return Response.integer(0);
+        return Response.integer(set.contains(member) ? 1 : 0);
+    }
+}


Test patch:
diff --git a/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java b/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
index 3b4d4c2..cc8b446 100644
--- a/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
+++ b/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
@@ -313,6 +313,15 @@ public class SimpleOperationsTest extends ComparisonBase {
         } while (poppedValue != null);
     }
 
+    @Theory
+    public void ensureSismemberReturnsCorrectValues(Jedis jedis){
+        String key = "my-set-key-sismember";
+        jedis.sadd(key, "A", "B");
+        assertTrue(jedis.sismember(key, "A"));
+        assertFalse(jedis.sismember(key, "C"));
+        assertFalse(jedis.sismember(key + "-nonexistent", "A"));
+    }
+
     @Theory
     public void whenHSettingOnTheSameKeys_EnsureReturnTypeIs1WhenKeysAreNew(Jedis jedis) {
         assertEquals(new Long(1L), jedis.hset(HASH, FIELD_1, VALUE_1));