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

how to use 'KEYS *' #63

Closed
yongjames opened this issue Sep 2, 2021 · 5 comments
Closed

how to use 'KEYS *' #63

yongjames opened this issue Sep 2, 2021 · 5 comments

Comments

@yongjames
Copy link

I want to get all keys in redis cluster,and i use "(redisReply *)redisClusterCommand(g_redis_cluster_conn, "KEYS *")", but , this returns NULL

please help me, much THX

@bjosv
Copy link
Collaborator

bjosv commented Sep 2, 2021

KEYS is currently not supported in the redisClusterCommand() which would send this command to each instance of the cluster.
The option would be to use redisClusterCommandToNode() instead, like this example:

nodeIterator ni;
initNodeIterator(&ni, cc);

cluster_node *node;
while ((node = nodeNext(&ni)) != NULL) {
    redisReply *reply;
    reply = redisClusterCommandToNode(cc, node, "KEYS *");
    ....
    freeReplyObject(reply);
}

But beware what the Redis docs warns about:
Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout. Don't use KEYS in your regular application code. If you're looking for a way to find keys in a subset of your keyspace, consider using SCAN or sets.

@yongjames
Copy link
Author

thanks !!!

@bjosv bjosv closed this as completed Sep 2, 2021
@youguys
Copy link

youguys commented Apr 2, 2022

the "nodeIterator ni" don't need to release ?

@zuiderkwast
Copy link
Collaborator

the "nodeIterator ni" don't need to release ?

Only if you malloc it. In the example above, it is stack allocated. initNodeIterator() doesn't allocate anything.

@youguys
Copy link

youguys commented Apr 6, 2022

the "nodeIterator ni" don't need to release ?

Only if you malloc it. In the example above, it is stack allocated. initNodeIterator() doesn't allocate anything.

Got it, thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants