-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
394 additions
and
17 deletions.
There are no files selected for viewing
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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/redis/clients/jedis/util/prefix/ClusterCommandArgumentsWithPrefixedKeys.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,20 @@ | ||
package redis.clients.jedis.util.prefix; | ||
|
||
import redis.clients.jedis.ClusterCommandArguments; | ||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.commands.ProtocolCommand; | ||
|
||
public class ClusterCommandArgumentsWithPrefixedKeys extends ClusterCommandArguments { | ||
private final byte[] prefixBytes; | ||
private final String prefixString; | ||
|
||
public ClusterCommandArgumentsWithPrefixedKeys(ProtocolCommand command, String prefixString, byte[] prefixBytes) { | ||
super(command); | ||
this.prefixString = prefixString; | ||
this.prefixBytes = prefixBytes; | ||
} | ||
|
||
public CommandArguments key(Object key) { | ||
return super.key(Prefixer.prefixKey(key, prefixString, prefixBytes)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/redis/clients/jedis/util/prefix/ClusterCommandObjectsWithPrefixedKeys.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 redis.clients.jedis.util.prefix; | ||
|
||
import redis.clients.jedis.ClusterCommandArguments; | ||
import redis.clients.jedis.ClusterCommandObjects; | ||
import redis.clients.jedis.commands.ProtocolCommand; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
public class ClusterCommandObjectsWithPrefixedKeys extends ClusterCommandObjects { | ||
private final String prefixString; | ||
private final byte[] prefixBytes; | ||
|
||
public ClusterCommandObjectsWithPrefixedKeys(String prefixString) { | ||
this.prefixString = prefixString; | ||
prefixBytes = SafeEncoder.encode(prefixString); | ||
} | ||
|
||
@Override | ||
protected ClusterCommandArguments commandArguments(ProtocolCommand command) { | ||
return new ClusterCommandArgumentsWithPrefixedKeys(command, prefixString, prefixBytes); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/redis/clients/jedis/util/prefix/CommandArgumentsWithPrefixedKeys.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,19 @@ | ||
package redis.clients.jedis.util.prefix; | ||
|
||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.commands.ProtocolCommand; | ||
|
||
public class CommandArgumentsWithPrefixedKeys extends CommandArguments { | ||
private final byte[] prefixBytes; | ||
private final String prefixString; | ||
|
||
public CommandArgumentsWithPrefixedKeys(ProtocolCommand command, String prefixString, byte[] prefixBytes) { | ||
super(command); | ||
this.prefixString = prefixString; | ||
this.prefixBytes = prefixBytes; | ||
} | ||
|
||
public CommandArguments key(Object key) { | ||
return super.key(Prefixer.prefixKey(key, prefixString, prefixBytes)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/redis/clients/jedis/util/prefix/CommandObjectsWithPrefixedKeys.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 redis.clients.jedis.util.prefix; | ||
|
||
import redis.clients.jedis.CommandArguments; | ||
import redis.clients.jedis.CommandObjects; | ||
import redis.clients.jedis.commands.ProtocolCommand; | ||
import redis.clients.jedis.util.SafeEncoder; | ||
|
||
public class CommandObjectsWithPrefixedKeys extends CommandObjects { | ||
private final String prefixString; | ||
private final byte[] prefixBytes; | ||
|
||
public CommandObjectsWithPrefixedKeys(String prefixString) { | ||
this.prefixString = prefixString; | ||
prefixBytes = SafeEncoder.encode(prefixString); | ||
} | ||
|
||
@Override | ||
protected CommandArguments commandArguments(ProtocolCommand command) { | ||
return new CommandArgumentsWithPrefixedKeys(command, prefixString, prefixBytes); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/redis/clients/jedis/util/prefix/Prefixer.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,34 @@ | ||
package redis.clients.jedis.util.prefix; | ||
|
||
import redis.clients.jedis.args.Rawable; | ||
import redis.clients.jedis.args.RawableFactory; | ||
|
||
final class Prefixer { | ||
private Prefixer() { | ||
} | ||
|
||
static Object prefixKey(Object key, String prefixString, byte[] prefixBytes) { | ||
if (key instanceof Rawable) { | ||
byte[] raw = ((Rawable) key).getRaw(); | ||
return RawableFactory.from(prefixKeyWithBytes(raw, prefixBytes)); | ||
} | ||
|
||
if (key instanceof byte[]) { | ||
return prefixKeyWithBytes((byte[]) key, prefixBytes); | ||
} | ||
|
||
if (key instanceof String) { | ||
String raw = (String) key; | ||
return prefixString + raw; | ||
} | ||
|
||
throw new IllegalArgumentException("\"" + key.toString() + "\" is not a valid argument."); | ||
} | ||
|
||
private static byte[] prefixKeyWithBytes(byte[] key, byte[] prefixBytes) { | ||
byte[] namespaced = new byte[prefixBytes.length + key.length]; | ||
System.arraycopy(prefixBytes, 0, namespaced, 0, prefixBytes.length); | ||
System.arraycopy(key, 0, namespaced, prefixBytes.length, key.length); | ||
return namespaced; | ||
} | ||
} |
Oops, something went wrong.