Getting rid of temp-xxxx.rdb files
When starting redis from a directory with a redis.conf
that includes:
save 60 10000
dir ./
it saves a temporary temp-1234.rdb
(with the number always changing) to keep persistence. Problem is, I fire up redis-server from inside my git repo and these temp files are generated there and show up as untracked.
Is there a way to keep redis from generating them (or generating them elsewhere)?
Or should I just add th开发者_运维问答em to .gitignore
?
You can change the default of dir ./
(current working directory) in redis.conf
to somewhere outside of your git repo.
# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
#dir ./
dir /home/octopus/redis_server/
You can change your Redis Persistence strategy by config the .conf file. but the temp-**.rdb will always locate in the same dir path which is ./ by default.
the numeric ** indicates the pid who belong to the process forked by redis server to save the DB on disk, a atomic rename is engaged after work completed. it exists just a while with the old rdb file.
whether you should add them to .gitignore depends your opportunity when execute "git add **". it chance to include when bgSaving is working just now. Of cause you could make such a rule with no harm only if you guarantee it excludes other normal files.
look up the rdb.c in redis src directory:
the line "snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());"
/* Save the DB on disk. Return REDIS_ERR on error, REDIS_OK on success */
int rdbSave(char *filename) {
dictIterator *di = NULL;
dictEntry *de;
char tmpfile[256];
char magic[10];
int j;
long long now = mstime();
FILE *fp;
rio rdb;
uint64_t cksum;
snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
fp = fopen(tmpfile,"w");
if (!fp) {
redisLog(REDIS_WARNING, "Failed opening .rdb for saving: %s",
strerror(errno));
return REDIS_ERR;
}
精彩评论