-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Proof-of-concept for automatic key prefixing #3770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a806a1
Proof-of-concept for automatic key prefixing
90a50b4
Iteration on key-prefixing POC
7098377
Second iteration on key-prefixing POC
02b8ba9
Address code review comments
66f6336
Attempt to fix cluster cleanup before/after prefix test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.