windows c++使用hiredis同步模式实现发布订阅

来源:互联网 发布:同花顺开户软件 编辑:程序博客网 时间:2024/06/05 18:46
void RedisSync(){redisContext* rc = redisConnect("127.0.0.1", 6379);if (rc == NULL || rc->err){return;}redisReply *reply = redisCommand(rc, "auth lls");freeReplyObject(reply);reply = redisCommand(rc, "subscribe luls");freeReplyObject(reply);while (redisGetReply(rc, (void **)&reply) == REDIS_OK){if (reply == NULL){return;}if (reply->type == REDIS_REPLY_ERROR){printf("Error: return [REDIS_REPLY_ERROR]%s\n", reply->str);}else if (reply->type == REDIS_REPLY_STATUS){if (stricmp(reply->str, "OK") != 0){printf("Error: return [REDIS_REPLY_STATUS]%s\n", reply->str);freeReplyObject(reply);return;}printf("return [REDIS_REPLY_STATUS]: %d\n", reply->str);}else if (reply->type == REDIS_REPLY_INTEGER){printf("return [REDIS_REPLY_INTEGER]: %l64d\n", reply->integer);}else if (reply->type == REDIS_REPLY_STRING){printf("return [REDIS_REPLY_STRING]: %s\n", reply->str);}else if (reply->type == REDIS_REPLY_ARRAY){for (int i = 0; i < reply->elements; i++){printf("%d)%s\n", i + 1, reply->element[i]->str);}printf("\n");}else if (reply->type == REDIS_REPLY_NIL){printf("return [REDIS_REPLY_NIL]: %s\n", reply->str);}freeReplyObject(reply);}redisFree(rc);}

0 0
原创粉丝点击