nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: fppt/jedis-mock
Pull request #19 (2019-01-28 13:53:37)

Implement Info


Patch:
diff --git a/README.md b/README.md
index e59ed98..754ae87 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,10 @@ server.setOptions(options);
 server.start();
 ```
 
+## Supported Operations
+
+All currently supported operations are listed [here](https://github.com/fppt/jedis-mock/blob/master/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java)
+
 ## Missing Operations
 
 If you get the following error:
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 3eb00c0..c931c26 100644
--- a/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
+++ b/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
@@ -77,6 +77,8 @@ public class OperationFactory {
 
     public static Optional<RedisOperation> buildMetaOperation(String name, OperationExecutorState state, List<Slice> params){
         switch(name){
+            case "info":
+                return Optional.of(new RO_info());
             case "multi":
                 return Optional.of(new RO_multi(state));
             case "select":
diff --git a/src/main/java/com/github/fppt/jedismock/operations/RO_info.java b/src/main/java/com/github/fppt/jedismock/operations/RO_info.java
new file mode 100644
index 0000000..e59a651
--- /dev/null
+++ b/src/main/java/com/github/fppt/jedismock/operations/RO_info.java
@@ -0,0 +1,11 @@
+package com.github.fppt.jedismock.operations;
+
+import com.github.fppt.jedismock.server.Response;
+import com.github.fppt.jedismock.server.Slice;
+
+class RO_info implements RedisOperation {
+    @Override
+    public Slice execute() {
+        return Response.bulkString(Slice.create("Redis Mock Server Info"));
+    }
+}


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 ba0236d..b081d92 100644
--- a/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
+++ b/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
@@ -17,6 +17,7 @@ import java.util.concurrent.Future;
 import static junit.framework.TestCase.assertTrue;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
 @RunWith(Theories.class)
@@ -338,4 +339,9 @@ public class SimpleOperationsTest extends ComparisonBase {
         jedis.hsetnx(HASH, FIELD_3, VALUE_2);
         assertEquals(VALUE_1, jedis.hget(HASH, FIELD_3));
     }
+
+    @Theory
+    public void whenGettingInfo_EnsureSomeDateIsReturned(Jedis jedis){
+        assertNotNull(jedis.info());
+    }
 }
Repository: fppt/jedis-mock
Pull request #47 (2019-06-03 18:35:57)

Add hexists support
Add hexists support


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 067721c..4e7142b 100644
--- a/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
+++ b/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
@@ -63,6 +63,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("hexists", RO_hexists::new);
         TRANSACTIONAL_OPERATIONS.put("hget", RO_hget::new);
         TRANSACTIONAL_OPERATIONS.put("hset", RO_hset::new);
         TRANSACTIONAL_OPERATIONS.put("hdel", RO_hdel::new);
diff --git a/src/main/java/com/github/fppt/jedismock/operations/RO_hexists.java b/src/main/java/com/github/fppt/jedismock/operations/RO_hexists.java
new file mode 100644
index 0000000..19b30af
--- /dev/null
+++ b/src/main/java/com/github/fppt/jedismock/operations/RO_hexists.java
@@ -0,0 +1,21 @@
+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;
+
+
+public class RO_hexists extends AbstractRedisOperation {
+    RO_hexists(RedisBase base, List<Slice> params) {
+        super(base, params);
+    }
+
+    Slice response() {
+        if (base().getValue(params().get(0), params().get(1)) == null){
+            return Response.integer(0);
+        }
+        return Response.integer(1);
+    }
+}
\ No newline at end of file


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 bbad2bb..f730542 100644
--- a/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
+++ b/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
@@ -294,6 +294,17 @@ public class SimpleOperationsTest extends ComparisonBase {
         assertEquals(value, jedis.hget(hash, field));
     }
 
+    @Theory
+    public void whenHSettingAndHGetting_EnsureValuesAreSetAndExist(Jedis jedis){
+        String field = "my-field";
+        String hash = "my-hash";
+        String value = "my-value";
+
+        assertNull(jedis.hget(hash, field));
+        jedis.hset(hash, field, value);
+        assertTrue(jedis.hexists(hash, field));
+    }
+
     @Theory
     public void whenHDeleting_EnsureValuesAreRemoved(Jedis jedis) {
         String field = "my-field-2";
Repository: fppt/jedis-mock
Pull request #76 (2020-01-07 05:54:23)

Consolidate changes
Returns the number of stored keys.


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 50b8ebf..8bc5514 100644
--- a/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
+++ b/src/main/java/com/github/fppt/jedismock/operations/OperationFactory.java
@@ -55,6 +55,7 @@ public class OperationFactory {
         TRANSACTIONAL_OPERATIONS.put("publish", RO_publish::new);
         TRANSACTIONAL_OPERATIONS.put("flushall", RO_flushall::new);
         TRANSACTIONAL_OPERATIONS.put("flushdb", RO_flushdb::new);
+        TRANSACTIONAL_OPERATIONS.put("dbsize", RO_dbsize::new);
         TRANSACTIONAL_OPERATIONS.put("lrem", RO_lrem::new);
         TRANSACTIONAL_OPERATIONS.put("ping", RO_ping::new);
         TRANSACTIONAL_OPERATIONS.put("keys", RO_keys::new);
diff --git a/src/main/java/com/github/fppt/jedismock/operations/RO_dbsize.java b/src/main/java/com/github/fppt/jedismock/operations/RO_dbsize.java
new file mode 100644
index 0000000..4f23c87
--- /dev/null
+++ b/src/main/java/com/github/fppt/jedismock/operations/RO_dbsize.java
@@ -0,0 +1,17 @@
+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_dbsize extends AbstractRedisOperation {
+    RO_dbsize(RedisBase base, List<Slice> params) {
+        super(base, params);
+    }
+
+    Slice response() {
+        return Response.integer(base().keys().size());
+    }
+}


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 e8e3372..3b4d4c2 100644
--- a/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
+++ b/src/test/java/com/github/fppt/jedismock/comparisontests/SimpleOperationsTest.java
@@ -910,6 +910,20 @@ public class SimpleOperationsTest extends ComparisonBase {
         assertTrue(ttl > 0);
     }
 
+    @Theory
+    public void dbSizeReturnsCount(Jedis jedis) {
+        jedis.flushDB();
+
+        jedis.hset(HASH, FIELD_1, VALUE_1);
+        jedis.hset(HASH, FIELD_2, VALUE_2);
+
+        jedis.set(FIELD_1, VALUE_1);
+
+        long result = jedis.dbSize();
+
+        assertEquals(2, result);
+    }
+
     @Theory
     public void hashExpires(Jedis jedis) throws InterruptedException {
         jedis.flushDB();
Repository: jakartaee/data
Pull request #496 (2024-02-28 08:21:48)

add Cursor.elements()
Currently, `PageRequest.Cursor` is not even `Iterable`, which means that any time you want to read its elements you have to use an archaic indexed `for` loop. If you want to actually pass the key values as a list, you have to repackage them manually.

This adds an `elements()` method which automatically packages the elements as an unmodifiable list.


Patch:
diff --git a/api/src/main/java/jakarta/data/page/KeysetCursor.java b/api/src/main/java/jakarta/data/page/KeysetCursor.java
index a875824e..11f2edc3 100644
--- a/api/src/main/java/jakarta/data/page/KeysetCursor.java
+++ b/api/src/main/java/jakarta/data/page/KeysetCursor.java
@@ -18,6 +18,7 @@
 package jakarta.data.page;
 
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * Built-in implementation of Cursor for keyset pagination.
@@ -60,6 +61,11 @@ class KeysetCursor implements PageRequest.Cursor {
         return keyset.length;
     }
 
+    @Override
+    public List<?> elements() {
+        return List.of(keyset);
+    }
+
     @Override
     public String toString() {
         return new StringBuilder(27).append("Cursor@").append(Integer.toHexString(hashCode()))
diff --git a/api/src/main/java/jakarta/data/page/PageRequest.java b/api/src/main/java/jakarta/data/page/PageRequest.java
index ae77f4ca..da7e4490 100644
--- a/api/src/main/java/jakarta/data/page/PageRequest.java
+++ b/api/src/main/java/jakarta/data/page/PageRequest.java
@@ -487,6 +487,14 @@ public interface PageRequest<T> {
          */
         int size();
 
+        /**
+         * An unmodifiable list of values in the keyset.
+         *
+         * @return an unmodifiable list containing the
+         *         ordered values
+         */
+        List<?> elements();
+
         /**
          * String representation of the keyset cursor, including the number of
          * key values in the cursor but not the values themselves.


Test patch:
diff --git a/api/src/test/java/jakarta/data/page/KeysetPageRequestTest.java b/api/src/test/java/jakarta/data/page/KeysetPageRequestTest.java
index df4ccd8f..0a6f9f4b 100644
--- a/api/src/test/java/jakarta/data/page/KeysetPageRequestTest.java
+++ b/api/src/test/java/jakarta/data/page/KeysetPageRequestTest.java
@@ -153,7 +153,7 @@ class KeysetPageRequestTest {
         PageRequest.Cursor cursor1 = new KeysetCursor("keyval1", '2', 3);
         PageRequest.Cursor cursor2 = new KeysetCursor("keyval2", '2', 3);
         PageRequest.Cursor cursor3 = new KeysetCursor("keyval1", '2');
-        PageRequest.Cursor cursor4 = new Pagination.Cursor() {
+        PageRequest.Cursor cursor4 = new PageRequest.Cursor() {
             private final Object[] keyset = new Object[] { "keyval1", '2', 3 };
 
             @Override
@@ -165,6 +165,11 @@ class KeysetPageRequestTest {
             public int size() {
                 return keyset.length;
             }
+
+            @Override
+            public List<?> elements() {
+                return List.of(keyset);
+            }
         };
 
         assertSoftly(softly -> {