Skip to content

Commit

Permalink
ISPN-14660 SUBSTR
Browse files Browse the repository at this point in the history
  • Loading branch information
jabolina committed Feb 14, 2024
1 parent 945f091 commit 6ef03aa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
21 changes: 18 additions & 3 deletions documentation/src/main/asciidoc/topics/ref_redis_commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ The {brandname} RESP endpoint implements the following Redis commands:
| link:https://redis.io/commands/getrange[GETRANGE]
|

| link:https://redis.io/commands/getset[GETSET]
| Deprecated. Use the `SET` command with the appropriate flags.

| link:https://redis.io/commands/hdel[HDEL]
|

Expand Down Expand Up @@ -215,6 +218,9 @@ for concurrent operations or failures unless the resp cache is configured to use
| link:https://redis.io/commands/mset[MSET]
|

| link:https://redis.io/commands/msetnx[MSETNX]
|

| link:https://redis.io/commands/multi[MULTI] [[multi_command]]
| The current implementation has a relaxed isolation level. Redis offers serializable transactions, but {{brandname}}
provides a read-uncommitted isolation.
Expand All @@ -225,12 +231,12 @@ provides a read-uncommitted isolation.
| link:https://redis.io/commands/pexpiretime[PEXPIRETIME]
|

| link:https://redis.io/commands/msetnx[MSETNX]
|

| link:https://redis.io/commands/ping[PING]
|

| link:https://redis.io/commands/psetex[PSETEX]
| Deprecated. Utilize `SET` with the appropriate flags.

| link:https://redis.io/commands/psubscribe[PSUBSCRIBE]
|

Expand Down Expand Up @@ -294,6 +300,12 @@ provides a read-uncommitted isolation.
| link:https://redis.io/commands/set[SET]
|

| link:https://redis.io/commands/setex[SETEX]
| Deprecated. Use the `SET` command with the appropriate flags.

| link:https://redis.io/commands/setnx[SETNX]
| Deprecated. Use the `SET` command with the appropriate flags.

| link:https://redis.io/commands/set[SETRANGE]
|

Expand Down Expand Up @@ -333,6 +345,9 @@ provides a read-uncommitted isolation.
| link:https://redis.io/commands/strlen[STRLEN]
|

| link:https://redis.io/commands/substr[SUBSTR]
| Deprecated. Use the `GETRANGE` command.

| link:https://redis.io/commands/subscribe[SUBSCRIBE]
|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
import org.infinispan.server.resp.commands.string.SETRANGE;
import org.infinispan.server.resp.commands.string.STRALGO;
import org.infinispan.server.resp.commands.string.STRLEN;
import org.infinispan.server.resp.commands.string.SUBSTR;
import org.infinispan.server.resp.commands.tx.DISCARD;
import org.infinispan.server.resp.commands.tx.EXEC;
import org.infinispan.server.resp.commands.tx.MULTI;
Expand Down Expand Up @@ -183,7 +184,7 @@ public final class Commands {
ALL_COMMANDS[16] = new RespCommand[]{new QUIT()};
ALL_COMMANDS[17] = new RespCommand[]{new RPUSH(), new RPUSHX(), new RPOP(), new RESET(), new READWRITE(), new READONLY(), new RPOPLPUSH(), new RENAME(), new RENAMENX() };
// SET should always be first here
ALL_COMMANDS[18] = new RespCommand[]{new SET(), new SETEX(), new SETNX(), new SMEMBERS(), new SISMEMBER(), new SADD(), new STRLEN(), new SMOVE(), new SCARD(), new SINTER(), new SINTERSTORE(), new SINTERCARD(), new SUNION(), new SUNIONSTORE(), new SPOP(), new SRANDMEMBER(), new SREM(), new SDIFF(), new SDIFFSTORE(), new SUBSCRIBE(), new SELECT(), new STRALGO(), new SCAN(), new SSCAN(), new SETRANGE(), new SORT(), new SORT_RO()};
ALL_COMMANDS[18] = new RespCommand[]{new SET(), new SETEX(), new SETNX(), new SMEMBERS(), new SISMEMBER(), new SADD(), new STRLEN(), new SMOVE(), new SCARD(), new SINTER(), new SINTERSTORE(), new SINTERCARD(), new SUNION(), new SUNIONSTORE(), new SPOP(), new SRANDMEMBER(), new SREM(), new SDIFF(), new SDIFFSTORE(), new SUBSCRIBE(), new SELECT(), new STRALGO(), new SCAN(), new SSCAN(), new SETRANGE(), new SORT(), new SORT_RO(), new SUBSTR()};
ALL_COMMANDS[19] = new RespCommand[]{new TTL(), new TYPE(), new TOUCH(), new TIME() };
ALL_COMMANDS[20] = new RespCommand[]{new UNSUBSCRIBE(), new UNWATCH()};
ALL_COMMANDS[22] = new RespCommand[]{new WATCH()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public CompletionStage<RespRequestHandler> perform(Resp3Handler handler,
}

private byte[] subrange(byte[] arr, int begin, int end) {
if (arr == null) return Util.EMPTY_BYTE_ARRAY;

// Deal with negative
if (begin < 0) {
begin = Math.max(0, arr.length + begin);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.infinispan.server.resp.commands.string;

/**
* `<code>SUBSTR key start end</code>` command.
* <p>
* This command is deprecated. The recommended alternative is `<code>GETRANGE key start end</code>`.
* </p>
*
* @since 15.0
* @author José Bolina
* @see GETRANGE
* @see <a href="https://redis.io/commands/substr/">Redis documentation</a>.
*/
public class SUBSTR extends GETRANGE { }
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ void testGetRange() {
assertThat(redis.getrange(key, 0, 0)).isEqualTo("");
// End before beginning
assertThat(redis.getrange(key, 3, 2)).isEqualTo("");
// Non-existent entry
assertThat(redis.getrange("something", 0, 10)).isEqualTo("");
}

@Test
Expand Down

0 comments on commit 6ef03aa

Please sign in to comment.