-
Notifications
You must be signed in to change notification settings - Fork 513
compatiable ror bitmap rdb type #1079
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
Open
jackjeyis
wants to merge
7
commits into
master
Choose a base branch
from
feature/rdb820
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1406f24
compatiable ror bitmap rdb type
04a3858
rdb type add version
beb548b
add conflict type into version map
758d1ad
support 8.2 new command
e807c09
support multi split
61e3910
RedisOpType add fields attr
22abb62
fix hashtag check & subkey parser merge general fields logic
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,11 @@ | |
| import com.ctrip.xpipe.redis.core.redis.operation.RedisOp; | ||
| import com.ctrip.xpipe.redis.core.redis.operation.RedisOpParser; | ||
| import com.ctrip.xpipe.redis.core.redis.operation.RedisOpType; | ||
| import com.ctrip.xpipe.redis.core.redis.operation.op.RedisOpMultiKVs; | ||
| import com.ctrip.xpipe.redis.core.redis.operation.op.RedisOpMultiSubKey; | ||
| import com.ctrip.xpipe.tuple.Pair; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.*; | ||
|
|
||
| /** | ||
| * @author tb | ||
|
|
@@ -24,12 +22,28 @@ public class RedisOpWithSubKeysParser extends AbstractRedisOpParser implements R | |
| private Integer kvNum; | ||
| private boolean kvReverse; | ||
|
|
||
| private byte[] NX_BYTES = new byte[]{'N','X'}; | ||
| private byte[] XX_BYTES = new byte[]{'X','X'}; | ||
| private byte[] GT_BYTES = new byte[]{'G','T'}; | ||
| private byte[] LT_BYTES = new byte[]{'L','T'}; | ||
| private byte[] CH_BYTES = new byte[]{'C','H'}; | ||
| private byte[] INCR_BYTES = new byte[]{'I','N','C','R'}; | ||
| private static final Set<ByteBuffer> NON_KEY_COMMANDS = new HashSet<>(); | ||
| private static final Set<ByteBuffer> NON_KEY_COMMANDS_WITH_ARGS = new HashSet<>(); | ||
|
|
||
| private static final byte[] FIELDS_BYTES = "FIELDS".getBytes(); | ||
| private static final byte[] FIELDS_BYTES_LOWER = "fields".getBytes(); | ||
|
|
||
| static { | ||
| // 无参数关键字 | ||
| String[] noArgCmds = { | ||
| "NX", "nx", "XX", "xx", "GT", "gt", "LT", "lt", "CH", "ch", | ||
| "INCR", "incr", "KEEPTTL", "keepttl", "FNX", "fnx", "FXX", "fxx", "PERSIST", "persist" | ||
| }; | ||
| for (String cmd : noArgCmds) { | ||
| NON_KEY_COMMANDS.add(ByteBuffer.wrap(cmd.getBytes())); | ||
| } | ||
| // 带一个参数的关键字 | ||
| String[] oneArgCmds = { "EX", "ex", "PX", "px", "EXAT", "exat", "PXAT", "pxat" }; | ||
| for (String cmd : oneArgCmds) { | ||
| NON_KEY_COMMANDS_WITH_ARGS.add(ByteBuffer.wrap(cmd.getBytes())); | ||
| NON_KEY_COMMANDS.add(ByteBuffer.wrap(cmd.getBytes())); // 也在无参数集合中,因为需要先识别 | ||
| } | ||
| } | ||
|
|
||
| public RedisOpWithSubKeysParser(RedisOpType redisOpType, int keyStartIndex, int kvNum,boolean kvReverse) { | ||
| this.redisOpType = redisOpType; | ||
|
|
@@ -43,6 +57,13 @@ public RedisOp parse(byte[][] args) { | |
| Pair<RedisOpType, byte[][]> pair = redisOpType.transfer(redisOpType, args); | ||
| args = pair.getValue(); | ||
|
|
||
| if(redisOpType.isFields()) { | ||
| return parseFieldsCommand(redisOpType,args); | ||
| } | ||
| return parseGeneralCommands(args, pair); | ||
| } | ||
|
|
||
| private RedisOpMultiSubKey parseGeneralCommands(byte[][] args, Pair<RedisOpType, byte[][]> pair) { | ||
| // 计算容量 - 主键 + 子键数量 | ||
| int subKeyCount = (args.length - keyStartIndex-1) / kvNum; | ||
| int capacity = 1 + subKeyCount; | ||
|
|
@@ -76,7 +97,7 @@ public RedisOp parse(byte[][] args) { | |
| subKeys.add(subKey); | ||
| } | ||
|
|
||
| return new RedisOpMultiSubKey(pair.getKey(), args, key,subKeys); | ||
| return new RedisOpMultiSubKey(pair.getKey(), args, key, subKeys); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -85,8 +106,38 @@ public int getOrder() { | |
| } | ||
|
|
||
| private boolean nonKey(byte[] args){ | ||
| return Arrays.equals(NX_BYTES,args) || Arrays.equals(XX_BYTES,args) | ||
| || Arrays.equals(GT_BYTES,args) || Arrays.equals(LT_BYTES,args) | ||
| || Arrays.equals(CH_BYTES,args) || Arrays.equals(INCR_BYTES,args); | ||
| return NON_KEY_COMMANDS.contains(ByteBuffer.wrap(args)); | ||
| } | ||
|
|
||
| private RedisOp parseFieldsCommand(RedisOpType opType, byte[][] args) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 和parseGeneralCommands的关系? |
||
| int idx = keyStartIndex; | ||
| RedisKey key = new RedisKey(args[idx++]); | ||
|
|
||
| // 跳过 FIELDS 之前的所有可选标志 | ||
| while (idx < args.length) { | ||
| ByteBuffer tokenBuf = ByteBuffer.wrap(args[idx]); | ||
| if (NON_KEY_COMMANDS.contains(tokenBuf)) { | ||
| idx++; | ||
| if (NON_KEY_COMMANDS_WITH_ARGS.contains(tokenBuf) && idx < args.length) { | ||
| idx++; // 跳过标志的参数 | ||
| } | ||
| } else if (Arrays.equals(args[idx], FIELDS_BYTES) || Arrays.equals(args[idx], FIELDS_BYTES_LOWER)) { | ||
| idx++; | ||
| break; | ||
| } else { | ||
| idx++; | ||
| } | ||
| } | ||
|
|
||
| if (idx >= args.length) throw new IllegalArgumentException("Missing numfields"); | ||
| int numFields = Integer.parseInt(new String(args[idx++])); | ||
| List<RedisKey> subKeys = new ArrayList<>(numFields); | ||
|
|
||
| for (int i = 0; i < numFields; i++) { | ||
| if (idx >= args.length) throw new IllegalArgumentException("Incomplete field list"); | ||
| subKeys.add(new RedisKey(args[idx])); | ||
| idx += kvNum; | ||
| } | ||
| return new RedisOpMultiSubKey(opType, args, key, subKeys); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
扫一下8.0注册了getkeyrequests_proc的命令,如果都符合可以用这种写法;否则可以参考下Redis的写法,对于特殊的key获取定义方法注册到命令定义枚举