Strange Redis SET command behaviour -


i'm writing simple program testing redis:

#include <hiredis.h> #include <cstdio>  int main() {     rediscontext * c = redisconnect("127.0.0.1", 6379);      redisreply * reply;      reply = rediscommand(c, "flushall");     freereplyobject(reply);      for(long int = 0; <= 1000000; i++)     {            char query[64];         sprintf(query, "set %ld \"string%ld\"", i, i);           reply = rediscommand(c, query);         freereplyobject(reply);          if( !(i % 100000) )         {                reply = rediscommand(c, "dbsize");             int res = reply->integer;             freereplyobject(reply);              printf("%s\n", query);             printf("dbsize: %d\n", res);         }        }         redisfree(c); } 

it should put 1000000 keys db, output following:

set 0 "string0" dbsize: 1 set 100000 "string100000" dbsize: 100001 set 200000 "string200000" dbsize: 200001 set 300000 "string300000" dbsize: 300001 set 400000 "string400000" dbsize: 400001 set 500000 "string500000" dbsize: 500001 set 600000 "string600000" dbsize: 600001 set 700000 "string700000" dbsize: 700001 set 800000 "string800000" dbsize: 779479 set 900000 "string900000" dbsize: 779479 set 1000000 "string1000000" dbsize: 779479 

so in 1 moment (usually after 600000 key) redis stops adding records. can reason of such behaviour?

you not check errors in code, difficult diagnose issue. suppose analyse output before freeing reply object.

the probable reason redis instance has been configured maxmemory limit, , have reached limit. may want check configuration file, or use following command:

config maxmemory 

a 0 value means there no limit. otherwise, limit epxressed in number of bytes.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -