Skip to content

Instantly share code, notes, and snippets.

@yoyicue
Last active January 2, 2016 18:49
Show Gist options
  • Save yoyicue/8346283 to your computer and use it in GitHub Desktop.
Save yoyicue/8346283 to your computer and use it in GitHub Desktop.
get all key/value in redis DB
#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);
}
}
@yoyicue
Copy link
Author

yoyicue commented Jan 10, 2014

git clone https://github.com/antirez/hiredis.git && cd hiredis && make && sudo make install && sudo ldconfig
curl -O https://gist.github.com/yoyicue/8346283/raw/59701165c107d2291268ec1b997b47210b42f27a/dump.c
gcc -m64 dump.c -o dump -lhiredis -I/usr/local/include/hiredis
./dump > dump.csv 2> stderr.txt 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment