-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Update KEYS and SCAN page with new optimization about pattern with hash tag. #2610
Conversation
👷 Deploy request for redis-doc pending review.Visit the deploys page to approve it
|
let's add the same comment about SCAN in this PR as well. |
Currently, there are several limitations when using hashtags in patterns. For instance, there cannot be wildcards or escape character before the hashtag, and the hashtag within curly braces cannot contain wildcards or support escape character. This is related to the implementation of the /* If it can be inferred that the given glob-style pattern, as implemented in
* stringmatchlen() in util.c, only can match keys belonging to a single slot,
* that slot is returned. Otherwise -1 is returned. */
int patternHashSlot(char *pattern, int length) {
int s = -1; /* index of the first '{' */
for (int i = 0; i < length; i++) {
if (pattern[i] == '*' || pattern[i] == '?' || pattern[i] == '[') {
/* Wildcard or character class found. Keys can be in any slot. */
return -1;
} else if (pattern[i] == '\\') {
/* Escaped character. Computing slot in this case is not
* implemented. We would need a temp buffer. */
return -1;
} else if (s == -1 && pattern[i] == '{') {
/* Opening brace '{' found. */
s = i;
} else if (s >= 0 && pattern[i] == '}' && i == s + 1) {
/* Empty tag '{}' found. The whole key is hashed. Ignore braces. */
s = -2;
} else if (s >= 0 && pattern[i] == '}') {
/* Non-empty tag '{...}' found. Hash what's between braces. */
return crc16(pattern + s + 1, i - s - 1) & 0x3FFF;
}
}
/* The pattern matches a single key. Hash the whole pattern. */
return crc16(pattern, length) & 0x3FFF;
} For example, "{abc}*" can successfully recognize the hashtag and only scan the slot corresponding to "abc". However, "*{abc}", "{a*c}", or "{a\*bc}" cannot recognize the hashtag. I believe we need @zuiderkwast 's help to carefully describe the rules for using hashtags in patterns. |
Co-authored-by: David Dougherty <david.dougherty@redis.com>
@oranagra @zuiderkwast please approve |
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.
Minor suggestions to formulation.
Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
As the optimization done in redis/redis#12754, we may doc this in the command page.