Skip to content
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

Modules: add RM_GetCommandKeys(). #7884

Merged
merged 2 commits into from
Oct 11, 2020
Merged

Conversation

yossigo
Copy link
Member

@yossigo yossigo commented Oct 5, 2020

This is essentially the same as calling COMMAND GETKEYS but provides a more efficient interface that can be used in every context (i.e. not a Redis command).

This pull request also includes refactoring of the getKeysFromCommand() interface to eliminate the previously used static buffer.

@yossigo yossigo requested a review from oranagra October 5, 2020 14:09
@yossigo yossigo added the state:major-decision Requires core team consensus label Oct 5, 2020
src/module.c Show resolved Hide resolved
src/module.c Outdated Show resolved Hide resolved
src/module.c Show resolved Hide resolved
src/module.c Outdated Show resolved Hide resolved
src/module.c Show resolved Hide resolved
src/module.c Show resolved Hide resolved
src/tracking.c Outdated Show resolved Hide resolved
src/db.c Outdated Show resolved Hide resolved
src/module.c Outdated
if (res->numkeys == res->size) {
/* If we're using the preallocated array, reallocate on the heap
* and move the data. Otherwise we can just realloc. */
int newsize = res->size * 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above a certain size, *2 may be too much.
we can consider just adding 1000 instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capping the doubling is reasonable but I wouldn't want to use intervals of 1000 on extreme cases.

src/module.c Outdated
@@ -672,12 +671,12 @@ int moduleGetCommandKeysViaAPI(struct redisCommand *cmd, robj **argv, int argc,
ctx.module = cp->module;
ctx.client = NULL;
ctx.flags |= REDISMODULE_CTX_KEYS_POS_REQUEST;
if (!result->keys) result->keys = result->keysbuf; /* Initialize to use preallocated array */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the init with the preallocated array already handled by the caller?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can't without a macro that takes the name of the variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh right, the caller does GETKEYS_RESULT_INIT which doesn't do that.
it's prepareGetKeysResult that does it (static and only used in db.c).
and it is designed to be used once (not repeatedly).

i guess what i was thinking is to make it non-static, and change it in a way that it can be called repeatedly, then it can be used in both moduleGetCommandKeysViaAPI (first init), and also in RM_KeyAtPos (doing the reallocs).

just a thought, your way is good too.

oranagra
oranagra previously approved these changes Oct 6, 2020
Avoid using a static buffer for short key index responses, and make it
caller's responsibility to stack-allocate a result type. Responses that
don't fit are still allocated on the heap.
This is essentially the same as calling COMMAND GETKEYS but provides a
more efficient interface that can be used in every context (i.e. not a
Redis command).
@yossigo yossigo merged commit 7d117d7 into redis:unstable Oct 11, 2020
@yossigo yossigo deleted the api-getkeys branch October 11, 2020 13:04
@oranagra oranagra mentioned this pull request Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:major-decision Requires core team consensus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants