Skip to content

Commit 1ae76dc

Browse files
committed
Update XCLAIM with options; remove LASTID
Signed-off-by: Andrew Carbonetto <[email protected]>
1 parent 884eda5 commit 1ae76dc

File tree

7 files changed

+151
-67
lines changed

7 files changed

+151
-67
lines changed

glide-core/src/client/value_conversion.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ pub(crate) fn expected_type_for_cmd(cmd: &Cmd) -> Option<ExpectedReturnType> {
858858
Some(ExpectedReturnType::ArrayOfStrings)
859859
} else {
860860
Some(ExpectedReturnType::Map {
861-
key_type: &Some(ExpectedReturnType::BulkString),
861+
key_type: &Some(ExpectedReturnType::SimpleString),
862862
value_type: &Some(ExpectedReturnType::ArrayOfStrings),
863863
})
864864
}
@@ -1192,6 +1192,21 @@ mod tests {
11921192
assert!(converted_4.is_err());
11931193
}
11941194

1195+
#[test]
1196+
fn convert_xclaim() {
1197+
assert!(matches!(
1198+
expected_type_for_cmd(redis::cmd("XCLAIM").arg("key").arg("grou").arg("consumer").arg("0").arg("id")),
1199+
Some(ExpectedReturnType::Map {
1200+
key_type: &Some(ExpectedReturnType::SimpleString),
1201+
value_type: &Some(ExpectedReturnType::ArrayOfStrings),
1202+
})
1203+
));
1204+
assert!(matches!(
1205+
expected_type_for_cmd(redis::cmd("XCLAIM").arg("key").arg("grou").arg("consumer").arg("0").arg("id").arg("JUSTID")),
1206+
Some(ExpectedReturnType::ArrayOfStrings)
1207+
));
1208+
}
1209+
11951210
#[test]
11961211
fn convert_xrange_xrevrange() {
11971212
assert!(matches!(

java/client/src/main/java/glide/api/BaseClient.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldReadOnlySubCommands;
88
import static glide.api.models.commands.bitmap.BitFieldOptions.BitFieldSubCommands;
99
import static glide.api.models.commands.bitmap.BitFieldOptions.createBitFieldArgs;
10+
import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API;
1011
import static glide.ffi.resolvers.SocketListenerResolver.getSocket;
1112
import static glide.utils.ArrayTransformUtils.cast3DArray;
1213
import static glide.utils.ArrayTransformUtils.castArray;
@@ -2024,8 +2025,8 @@ public CompletableFuture<Map<String, String[]>> xclaim(
20242025
@NonNull String[] ids,
20252026
@NonNull StreamClaimOptions options) {
20262027
String[] args =
2027-
concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids);
2028-
args = concatenateArrays(args, options.toArgs(false));
2028+
concatenateArrays(
2029+
new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids, options.toArgs());
20292030
return commandManager.submitNewCommand(XClaim, args, this::handleMapResponse);
20302031
}
20312032

@@ -2036,8 +2037,13 @@ public CompletableFuture<String[]> xclaimJustId(
20362037
@NonNull String consumer,
20372038
long minIdleTime,
20382039
@NonNull String[] ids) {
2039-
return xclaimJustId(
2040-
key, group, consumer, minIdleTime, ids, StreamClaimOptions.builder().build());
2040+
String[] args =
2041+
concatenateArrays(
2042+
new String[] {key, group, consumer, Long.toString(minIdleTime)},
2043+
ids,
2044+
new String[] {JUST_ID_REDIS_API});
2045+
return commandManager.submitNewCommand(
2046+
XClaim, args, response -> castArray(handleArrayResponse(response), String.class));
20412047
}
20422048

20432049
@Override
@@ -2049,8 +2055,11 @@ public CompletableFuture<String[]> xclaimJustId(
20492055
@NonNull String[] ids,
20502056
@NonNull StreamClaimOptions options) {
20512057
String[] args =
2052-
concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids);
2053-
args = concatenateArrays(args, options.toArgs(true));
2058+
concatenateArrays(
2059+
new String[] {key, group, consumer, Long.toString(minIdleTime)},
2060+
ids,
2061+
options.toArgs(),
2062+
new String[] {JUST_ID_REDIS_API});
20542063
return commandManager.submitNewCommand(
20552064
XClaim, args, response -> castArray(handleArrayResponse(response), String.class));
20562065
}

java/client/src/main/java/glide/api/models/BaseTransaction.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static glide.api.models.commands.function.FunctionListOptions.LIBRARY_NAME_REDIS_API;
2121
import static glide.api.models.commands.function.FunctionListOptions.WITH_CODE_REDIS_API;
2222
import static glide.api.models.commands.function.FunctionLoadOptions.REPLACE;
23+
import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API;
2324
import static glide.utils.ArrayTransformUtils.concatenateArrays;
2425
import static glide.utils.ArrayTransformUtils.convertMapToKeyValueStringArray;
2526
import static glide.utils.ArrayTransformUtils.convertMapToValueKeyStringArray;
@@ -3296,7 +3297,10 @@ public T xclaim(
32963297
@NonNull String consumer,
32973298
long minIdleTime,
32983299
@NonNull String[] ids) {
3299-
return xclaim(key, group, consumer, minIdleTime, ids, StreamClaimOptions.builder().build());
3300+
String[] args =
3301+
concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids);
3302+
protobufTransaction.addCommands(buildCommand(XClaim, buildArgs(args)));
3303+
return getThis();
33003304
}
33013305

33023306
/**
@@ -3320,8 +3324,8 @@ public T xclaim(
33203324
@NonNull String[] ids,
33213325
@NonNull StreamClaimOptions options) {
33223326
String[] args =
3323-
concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids);
3324-
args = concatenateArrays(args, options.toArgs(false));
3327+
concatenateArrays(
3328+
new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids, options.toArgs());
33253329
protobufTransaction.addCommands(buildCommand(XClaim, buildArgs(args)));
33263330
return getThis();
33273331
}
@@ -3344,8 +3348,13 @@ public T xclaimJustId(
33443348
@NonNull String consumer,
33453349
long minIdleTime,
33463350
@NonNull String[] ids) {
3347-
return xclaimJustId(
3348-
key, group, consumer, minIdleTime, ids, StreamClaimOptions.builder().build());
3351+
String[] args =
3352+
concatenateArrays(
3353+
new String[] {key, group, consumer, Long.toString(minIdleTime)},
3354+
ids,
3355+
new String[] {JUST_ID_REDIS_API});
3356+
protobufTransaction.addCommands(buildCommand(XClaim, buildArgs(args)));
3357+
return getThis();
33493358
}
33503359

33513360
/**
@@ -3369,8 +3378,11 @@ public T xclaimJustId(
33693378
@NonNull String[] ids,
33703379
@NonNull StreamClaimOptions options) {
33713380
String[] args =
3372-
concatenateArrays(new String[] {key, group, consumer, Long.toString(minIdleTime)}, ids);
3373-
args = concatenateArrays(args, options.toArgs(true));
3381+
concatenateArrays(
3382+
new String[] {key, group, consumer, Long.toString(minIdleTime)},
3383+
ids,
3384+
options.toArgs(),
3385+
new String[] {JUST_ID_REDIS_API});
33743386
protobufTransaction.addCommands(buildCommand(XClaim, buildArgs(args)));
33753387
return getThis();
33763388
}

java/client/src/main/java/glide/api/models/commands/stream/StreamClaimOptions.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public class StreamClaimOptions {
3030
/** Redis api string to designate JUSTID */
3131
public static final String JUST_ID_REDIS_API = "JUSTID";
3232

33-
/** Redis api string to designate LASTID */
34-
public static final String LAST_ID_REDIS_API = "LASTID";
35-
3633
/**
3734
* Set the idle time (last time it was delivered) of the message. If <code>idle</code> is not
3835
* specified, an <code>idle</code> of <code>0</code> is assumed, that is, the time count is reset
@@ -63,9 +60,6 @@ public class StreamClaimOptions {
6360
*/
6461
private final boolean isForce;
6562

66-
/** Filter up to the <code>lastid</code> when claiming messages */
67-
private final String lastId;
68-
6963
public static class StreamClaimOptionsBuilder {
7064

7165
/**
@@ -83,7 +77,7 @@ public StreamClaimOptionsBuilder force() {
8377
*
8478
* @return String[]
8579
*/
86-
public String[] toArgs(boolean isJustId) {
80+
public String[] toArgs() {
8781
List<String> optionArgs = new ArrayList<>();
8882

8983
if (idle != null) {
@@ -105,15 +99,6 @@ public String[] toArgs(boolean isJustId) {
10599
optionArgs.add(FORCE_REDIS_API);
106100
}
107101

108-
if (isJustId) {
109-
optionArgs.add(JUST_ID_REDIS_API);
110-
}
111-
112-
if (lastId != null) {
113-
optionArgs.add(LAST_ID_REDIS_API);
114-
optionArgs.add(lastId);
115-
}
116-
117102
return optionArgs.toArray(new String[0]);
118103
}
119104
}

java/client/src/test/java/glide/api/RedisClientTest.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import static glide.api.models.commands.stream.StreamClaimOptions.FORCE_REDIS_API;
4242
import static glide.api.models.commands.stream.StreamClaimOptions.IDLE_REDIS_API;
4343
import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API;
44-
import static glide.api.models.commands.stream.StreamClaimOptions.LAST_ID_REDIS_API;
4544
import static glide.api.models.commands.stream.StreamClaimOptions.RETRY_COUNT_REDIS_API;
4645
import static glide.api.models.commands.stream.StreamClaimOptions.TIME_REDIS_API;
4746
import static glide.api.models.commands.stream.StreamGroupOptions.ENTRIES_READ_REDIS_API;
@@ -5835,13 +5834,7 @@ public void xclaim_with_options_returns_success() {
58355834
Long minIdleTime = 18L;
58365835
String[] ids = new String[] {"testId"};
58375836
StreamClaimOptions options =
5838-
StreamClaimOptions.builder()
5839-
.force()
5840-
.idle(11L)
5841-
.idleUnixTime(12L)
5842-
.retryCount(5L)
5843-
.lastId("2345-5")
5844-
.build();
5837+
StreamClaimOptions.builder().force().idle(11L).idleUnixTime(12L).retryCount(5L).build();
58455838
String[] arguments =
58465839
new String[] {
58475840
key,
@@ -5855,9 +5848,7 @@ public void xclaim_with_options_returns_success() {
58555848
"12",
58565849
RETRY_COUNT_REDIS_API,
58575850
"5",
5858-
FORCE_REDIS_API,
5859-
LAST_ID_REDIS_API,
5860-
"2345-5"
5851+
FORCE_REDIS_API
58615852
};
58625853
Map<String, String[]> mockResult = Map.of("1234-0", new String[] {"message", "log"});
58635854

@@ -5917,13 +5908,7 @@ public void xclaimJustId_with_options_returns_success() {
59175908
Long minIdleTime = 18L;
59185909
String[] ids = new String[] {"testId"};
59195910
StreamClaimOptions options =
5920-
StreamClaimOptions.builder()
5921-
.force()
5922-
.idle(11L)
5923-
.idleUnixTime(12L)
5924-
.retryCount(5L)
5925-
.lastId("2345-5")
5926-
.build();
5911+
StreamClaimOptions.builder().force().idle(11L).idleUnixTime(12L).retryCount(5L).build();
59275912
String[] arguments =
59285913
new String[] {
59295914
key,
@@ -5938,9 +5923,7 @@ public void xclaimJustId_with_options_returns_success() {
59385923
RETRY_COUNT_REDIS_API,
59395924
"5",
59405925
FORCE_REDIS_API,
5941-
JUST_ID_REDIS_API,
5942-
LAST_ID_REDIS_API,
5943-
"2345-5"
5926+
JUST_ID_REDIS_API
59445927
};
59455928
String[] mockResult = {"message", "log"};
59465929

java/client/src/test/java/glide/api/models/TransactionTests.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static glide.api.models.commands.stream.StreamClaimOptions.FORCE_REDIS_API;
3232
import static glide.api.models.commands.stream.StreamClaimOptions.IDLE_REDIS_API;
3333
import static glide.api.models.commands.stream.StreamClaimOptions.JUST_ID_REDIS_API;
34-
import static glide.api.models.commands.stream.StreamClaimOptions.LAST_ID_REDIS_API;
3534
import static glide.api.models.commands.stream.StreamClaimOptions.RETRY_COUNT_REDIS_API;
3635
import static glide.api.models.commands.stream.StreamClaimOptions.TIME_REDIS_API;
3736
import static glide.api.models.commands.stream.StreamGroupOptions.ENTRIES_READ_REDIS_API;
@@ -882,13 +881,7 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)),
882881
results.add(Pair.of(XClaim, buildArgs("key", "group", "consumer", "99", "12345-1", "98765-4")));
883882

884883
StreamClaimOptions claimOptions =
885-
StreamClaimOptions.builder()
886-
.force()
887-
.idle(11L)
888-
.idleUnixTime(12L)
889-
.retryCount(5L)
890-
.lastId("2345-5")
891-
.build();
884+
StreamClaimOptions.builder().force().idle(11L).idleUnixTime(12L).retryCount(5L).build();
892885
transaction.xclaim(
893886
"key", "group", "consumer", 99L, new String[] {"12345-1", "98765-4"}, claimOptions);
894887
results.add(
@@ -907,9 +900,7 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)),
907900
"12",
908901
RETRY_COUNT_REDIS_API,
909902
"5",
910-
FORCE_REDIS_API,
911-
LAST_ID_REDIS_API,
912-
"2345-5")));
903+
FORCE_REDIS_API)));
913904

914905
transaction.xclaimJustId("key", "group", "consumer", 99L, new String[] {"12345-1", "98765-4"});
915906
results.add(
@@ -936,9 +927,7 @@ InfScoreBound.NEGATIVE_INFINITY, new ScoreBoundary(3, false), new Limit(1, 2)),
936927
RETRY_COUNT_REDIS_API,
937928
"5",
938929
FORCE_REDIS_API,
939-
JUST_ID_REDIS_API,
940-
LAST_ID_REDIS_API,
941-
"2345-5")));
930+
JUST_ID_REDIS_API)));
942931

943932
transaction.time();
944933
results.add(Pair.of(Time, buildArgs()));

0 commit comments

Comments
 (0)