forked from fppt/jedis-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add blocking operations for SortedSets (#208)
* Add blocking operations for SortedSets * clean up code --------- Co-authored-by: Ivan Ponomarev <[email protected]>
- Loading branch information
1 parent
5a6e794
commit adb7c06
Showing
28 changed files
with
1,514 additions
and
421 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/github/fppt/jedismock/operations/sortedsets/BZMPop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.fppt.jedismock.operations.sortedsets; | ||
|
||
import com.github.fppt.jedismock.datastructures.Slice; | ||
import com.github.fppt.jedismock.exception.ArgumentException; | ||
import com.github.fppt.jedismock.operations.RedisCommand; | ||
import com.github.fppt.jedismock.storage.OperationExecutorState; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.github.fppt.jedismock.Utils.toNanoTimeout; | ||
|
||
@RedisCommand("bzmpop") | ||
public class BZMPop extends BZPop { | ||
private Slice numKeys; | ||
|
||
BZMPop(OperationExecutorState state, List<Slice> params) { | ||
super(state, params); | ||
|
||
} | ||
|
||
@Override | ||
protected void doOptionalWork(){ | ||
if (params().size() < 4) { | ||
throw new ArgumentException("ERR wrong number of arguments for 'bzmpop' command"); | ||
} | ||
timeoutNanos = toNanoTimeout(params().get(0).toString()); | ||
params().remove(0); | ||
ZMPop zmPop = new ZMPop(base(), new ArrayList<>(params())); | ||
numKeys = params().remove(0); | ||
keys = zmPop.parseArgs(); | ||
keys.remove(0); | ||
} | ||
|
||
@Override | ||
protected Slice popper(List<Slice> params) { | ||
List<Slice> newParams = new ArrayList<>(params()); | ||
newParams.add(0, numKeys); | ||
ZMPop zmPop = new ZMPop(base(), newParams); | ||
return zmPop.response(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/github/fppt/jedismock/operations/sortedsets/BZPop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.fppt.jedismock.operations.sortedsets; | ||
|
||
import com.github.fppt.jedismock.datastructures.Slice; | ||
import com.github.fppt.jedismock.operations.AbstractBPop; | ||
import com.github.fppt.jedismock.operations.AbstractRedisOperation; | ||
import com.github.fppt.jedismock.storage.OperationExecutorState; | ||
import com.github.fppt.jedismock.storage.RedisBase; | ||
|
||
import java.util.List; | ||
|
||
abstract class BZPop extends AbstractBPop { | ||
|
||
BZPop(OperationExecutorState state, List<Slice> params) { | ||
super(state, params); | ||
} | ||
|
||
@Override | ||
protected AbstractRedisOperation getSize(RedisBase base, List<Slice> params) { | ||
return new ZCard(base(), params); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/github/fppt/jedismock/operations/sortedsets/BZPopMax.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.fppt.jedismock.operations.sortedsets; | ||
|
||
import com.github.fppt.jedismock.datastructures.Slice; | ||
import com.github.fppt.jedismock.operations.RedisCommand; | ||
import com.github.fppt.jedismock.server.Response; | ||
import com.github.fppt.jedismock.storage.OperationExecutorState; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.github.fppt.jedismock.Utils.toNanoTimeout; | ||
|
||
@RedisCommand("bzpopmax") | ||
public class BZPopMax extends BZPop { | ||
|
||
BZPopMax(OperationExecutorState state, List<Slice> params) { | ||
super(state, params); | ||
timeoutNanos = toNanoTimeout(params().get(params().size() - 1).toString()); | ||
} | ||
|
||
@Override | ||
protected Slice popper(List<Slice> params) { | ||
List<Slice> result = new ZPop(base(), params, true).pop(); | ||
return Response.array(Arrays.asList(Response.bulkString(params.get(0)), result.get(0), result.get(1))); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/github/fppt/jedismock/operations/sortedsets/BZPopMin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.fppt.jedismock.operations.sortedsets; | ||
|
||
import com.github.fppt.jedismock.datastructures.Slice; | ||
import com.github.fppt.jedismock.operations.RedisCommand; | ||
import com.github.fppt.jedismock.server.Response; | ||
import com.github.fppt.jedismock.storage.OperationExecutorState; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.github.fppt.jedismock.Utils.toNanoTimeout; | ||
|
||
@RedisCommand("bzpopmin") | ||
public class BZPopMin extends BZPop { | ||
|
||
BZPopMin(OperationExecutorState state, List<Slice> params) { | ||
super(state, params); | ||
timeoutNanos = toNanoTimeout(params().get(params().size() - 1).toString()); | ||
} | ||
|
||
@Override | ||
protected Slice popper(List<Slice> params) { | ||
List<Slice> result = new ZPop(base(), params, false).pop(); | ||
return Response.array(Arrays.asList(Response.bulkString(params.get(0)), result.get(0), result.get(1))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.