c++读写redis-简单key-value

先从redis服务端获取一个简单的key-value

#include <hiredis/hiredis.h>
#include <iostream>
#include "third/nlohmann/json.hpp"
#include <map>

using namespace nlohmann;
using namespace std;

int main()
{
    redisContext *pContext = redisConnect("ubuntu机器ip", 6379);
    if (pContext->err)
    {
        redisFree(pContext);
        cout << "connect to redisServer fail" << endl;
    }
    cout << "connect to redisServer success" << endl;
    

    redisReply *pReply = (redisReply*)redisCommand(pContext, "get update2label");
    // cout << pReply->str << endl;
    string s = pReply->str;
    map<string,string> info = json::parse(s);
    cout << info.size() << endl;

    int i = 0;
    for (auto item:info)
    {
        i = i + 1;
        if (i % 1000 == 0)
        {cout << i << ", " <<item.first << " : " << item.second << endl;}
    }

    freeReplyObject(pReply);
    redisFree(pContext);
}
connect to redisServer success
12907
1000, 124-489-xx_1675730586_0.jpg : 0764#_6990.jpg
2000, 150-345-xx_1675734332_0.jpg : 0617#_5473.jpg
3000, 175-422-xx_1675740403_0.jpg : 0609#_5418.jpg
4000, 200-397-xx_1675731164_0.jpg : 0989#_8647.jpg
5000, 224-322-xx_1675742018_0.jpg : 0771#_7069.jpg
6000, 250-342-xx_1675747507_0.jpg : 0194#_1842.jpg
7000, 275-378-xx_1675742862_0.jpg : 0260#_2621.jpg
8000, 300-496-xx_1675741224_0.jpg : 0290#_3040.jpg
9000, 324-406-xx_1675732861_0.jpg : 1362#_12065.jpg
10000, 348-451-xx_1675730694_0.jpg : 1069#_9313.jpg
11000, 373-306-xx_1675742227_0.jpg : 0207#_1947.jpg
12000, 398-446-xx_1675748393_0.jpg : 0183#_1667.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值