errstr返回錯誤磁盤空間不足" type="hidden"/>

C++問題--Reis連接redisContext *pRedisContext = redisConnectWithTimeout("127.0.0.1", 6379, tv);pRedisContext->errstr返回錯誤磁盤空間不足


一、問題

使用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中進行設置:

 

 

 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM