Skip to content

Commit

Permalink
fix #158
Browse files Browse the repository at this point in the history
  • Loading branch information
tonivade committed Aug 16, 2023
1 parent 07a7a26 commit 6efe2c4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=2.1
version=2.1.1-SNAPSHOT

joptVersion=5.0.4
logbackVersion=1.3.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RedisToken execute(Database db, Request request) {
db.merge(safeKey(request.getParam(0)), DatabaseValue.EMPTY_LIST,
(oldValue, newValue) -> {
List<SafeString> list = oldValue.getList();
if (list.size() > 1) {
if (!list.isEmpty()) {
removed.add(list.get(0));
}
return list(list.stream().skip(1).collect(toList()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public RedisToken execute(Database db, Request request) {
(oldValue, newValue) -> {
List<SafeString> copy = new ArrayList<>(oldValue.getList());
Collections.reverse(copy);
if (copy.size() > 1) {
if (!copy.isEmpty()) {
removed.add(copy.remove(0));
}
Collections.reverse(copy);
Expand Down
12 changes: 12 additions & 0 deletions lib/src/test/java/com/github/tonivade/claudb/ClauDBServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ void testNotExist() {
});
}

@Test
public void testPushPull() {
execute(jedis -> {
long push = jedis.rpush("key", "val1", "val2");
String pop1 = jedis.rpop("key");
String pop2 = jedis.rpop("key");
assertThat(push, is(2l));
assertThat(pop1, equalTo("val2"));
assertThat(pop2, equalTo("val1"));
});
}

private void execute(Consumer<Jedis> action) {
try (Jedis jedis = createClientConnection()) {
action.accept(jedis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public void testExecute() {
.execute()
.assertValue("key", isList("b", "c"))
.assertThat(string("a"));


rule.withData("key", list("a"))
.withParams("key")
.execute()
.assertValue("key", isList())
.assertThat(string("a"));

rule.withData("key", list())
.withParams("key")
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public void testExecute() {
.assertValue("key", isList("a", "b"))
.assertThat(string("c"));

rule.withData("key", list("a"))
.withParams("key")
.execute()
.assertValue("key", isList())
.assertThat(string("a"));

rule.withData("key", list())
.withParams("key")
.execute()
Expand Down

0 comments on commit 6efe2c4

Please sign in to comment.