C++问题--Reis连接redisContext *pRedisContext = redisConnectWithTimeout("127.0.0.1", 6379, tv);pRedisCont...

一、问题

使用C++连接Redis的时候出错,错误String为磁盘空间不足,连接代码如下:

//reids默认监听端口6387
    int iTimeout = 10000;
    struct timeval tv;
    tv.tv_sec = iTimeout / 1000;
    tv.tv_usec = iTimeout * 1000;

    redisContext *pRedisContext = redisConnectWithTimeout("127.0.0.1", 6379, tv);
    if (NULL == pRedisContext || pRedisContext->err)
    {
        printf("%s \r\n", pRedisContext->errstr);
        printf("Connect to redis server failed \n");
        return -1;
    }

  返回错误值打印:

 

二、原因

  出现这个问题的原因是:  

    1. redis的设置的占用内存太大,例如, 电脑的内存是物理内存是8GB,最大的文件设置内存是 (8)+(2*8) GB为24GB.

    2.也可能是 maxheap 标识有问题,  这个是因为位置文件中少了maxheap的配置  

 

  这个问题已经在Redis.windows.conf里面说明:

# WARNING: not setting maxmemory will cause Redis to terminate with an
# out-of-memory exception if the heap limit is reached.
#

 

 三、解决办法步骤

  1. 去除 redis.windows.conf 中# maxmemory <bytes>前的#号,并写上bytes为10240000,如下:

# WARNING: not setting maxmemory will cause Redis to terminate with an
# out-of-memory exception if the heap limit is reached.
#
# NOTE: since Redis uses the system paging file to allocate the heap memory,
# the Working Set memory usage showed by the Windows Task Manager or by other
# tools such as ProcessExplorer will not always be accurate. For example, right
# after a background save of the RDB or the AOF files, the working set value
# may drop significantly. In order to check the correct amount of memory used
# by the redis-server to store the data, use the INFO client command. The INFO
# command shows only the memory used to store the redis data, not the extra
# memory used by the Windows process for its own requirements. Th3 extra amount
# of memory not reported by the INFO command can be calculated subtracting the
# Peak Working Set reported by the Windows Task Manager and the used_memory_peak
# reported by the INFO command.
#
maxmemory 2gb

2.  修改连接方式为redisConnect,若需要使用超时设定,请在redis.windows.conf中进行设置:

 

 

 

  

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值