-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 select different db execution "keys *" #1120
Comments
Using |
As @bjosv says, you should check to make sure the #include <hiredis/hiredis.h>
#include <string.h>
#include <assert.h>
#include <hiredis/hiredis.h>
#include <string.h>
#include <assert.h>
int main(void) {
redisContext *_redisCtx;
redisReply *_reply;
_redisCtx = (redisContext*)redisConnect("localhost", 6379);
assert(_redisCtx != NULL && _redisCtx->err == 0);
_reply = (redisReply*)redisCommand(_redisCtx, "select 1");
assert(_reply != NULL && _reply->type == REDIS_REPLY_STATUS &&
_reply->len == 2 && !strcmp(_reply->str, "OK"));
freeReplyObject(_reply);
_reply = (redisReply*)redisCommand(_redisCtx, "keys *");
assert(_reply != NULL && _reply->type == REDIS_REPLY_ARRAY);
for (size_t i = 0; i < _reply->elements; i++) {
assert(_reply->element[i]->type == REDIS_REPLY_STRING);
printf("KEY[%zu]: %s\n", i, _reply->element[i]->str);
}
freeReplyObject(_reply);
redisFree(_redisCtx);
} Cluster mode being enabled is the most likely issue (as it disables database numbers) but you can also verify this via I'm going to close this issue since it's unlikely to be a bug in hiredis but I'm happy to help you figure it out. 😄 |
Your reply solved my problem. Thank you! |
Through the example you gave, I checked my code and found that reply->len==43, when "select %s", a vector parameter value forgot to convert to c_str(). Thank you! |
question:
The keys I got are all in the database db0.
I need to select different db to get all keys at the same time, what do I need to do. thanks!
The text was updated successfully, but these errors were encountered: