* On error -1 is returned.
* On success if the key was actaully saved 1 is returned, otherwise 0
* is returned (the key was already expired). */
-int rdbSaveKeyValuePair(FILE *fp, redisDb *db, robj *key, robj *val,
- time_t now)
+int rdbSaveKeyValuePair(FILE *fp, robj *key, robj *val,
+ time_t expiretime, time_t now)
{
- time_t expiretime;
-
- expiretime = getExpire(db,key);
-
/* Save the expire time */
if (expiretime != -1) {
/* If this key is already expired skip it */
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
fp = fopen(tmpfile,"w");
if (!fp) {
- redisLog(REDIS_WARNING, "Failed saving the DB: %s", strerror(errno));
+ redisLog(REDIS_WARNING, "Failed opening .rdb for saving: %s",
+ strerror(errno));
return REDIS_ERR;
}
if (fwrite("REDIS0001",9,1,fp) == 0) goto werr;
while((de = dictNext(di)) != NULL) {
sds keystr = dictGetEntryKey(de);
robj key, *o = dictGetEntryVal(de);
+ time_t expire;
initStaticStringObject(key,keystr);
- if (rdbSaveKeyValuePair(fp,db,&key,o,now) == -1) goto werr;
+ expire = getExpire(db,&key);
+ if (rdbSaveKeyValuePair(fp,&key,o,expire,now) == -1) goto werr;
}
dictReleaseIterator(di);
}
if (server.ds_enabled) {
cacheForcePointInTime();
- return dsRdbSave(filename);
+ return dsRdbSaveBackground(filename);
}
if ((childpid = fork()) == 0) {
}
void saveCommand(redisClient *c) {
- if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread-t)-1) {
+ if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t)-1) {
addReplyError(c,"Background save already in progress");
return;
}
}
void bgsaveCommand(redisClient *c) {
- if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread-t)-1) {
+ if (server.bgsavechildpid != -1 || server.bgsavethread != (pthread_t)-1) {
addReplyError(c,"Background save already in progress");
return;
}