Last active
January 2, 2016 18:49
-
-
Save yoyicue/8346283 to your computer and use it in GitHub Desktop.
get all key/value in redis DB
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include "hiredis.h" | |
int main(void) | |
{ | |
unsigned int i,j=0;char **str1; | |
redisContext *c; char *t; | |
redisReply *reply, *rep; | |
struct timeval timeout = { 1, 500000 }; // 1.5 seconds | |
c = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout); | |
if (c->err) { | |
printf("Connection error: %s\n", c->errstr); | |
exit(1); | |
} | |
reply = redisCommand(c,"keys *"); | |
while ( j<reply->elements && reply->element[j]->str != NULL) | |
{ | |
rep = redisCommand(c,"GET %s", reply->element[j]->str); | |
if (strstr(rep->str,"ERR Operation against a key holding")) | |
{ | |
printf("%s,%s\n", reply->element[j]->str,rep->str); | |
break; | |
} | |
printf("%s,%s\n", reply->element[j]->str,rep->str); | |
j++; | |
freeReplyObject(rep); | |
} | |
} |
Author
yoyicue
commented
Jan 10, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment