hiredis是操作redis的C库。
使用hiredis 的scan遍历redis中得到打印所有key,将其中属于hash的key的键值对也打印出来,示例:
#include <hiredis/hiredis.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
redisContext *_connect;
redisReply *_reply = NULL;
_connect = redisConnect(config->redis->ip.c_str(), config->redis->port);
if (NULL == _connect || _connect->err ) {
if(_connect){
printf("error:%s\n",_connect->errstr);
} else {
printf("init redis failed");
}
return;
}
int index = 0;
do{
_reply = (redis *)redisCommand(_connect,"scan %d",index);
if (NULL == _reply) {
printf("redisCommand execute failed");
redisFree(_connect);
break;
}
if (_reply->type != REDIS_REPLY_ARRAY) {