From 91d664d6ce3d85a5b282a3945153d78e2474640f Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 8 Mar 2012 10:13:12 +0100 Subject: [PATCH] run_id added to INFO output. The Run ID is a field that identifies a single execution of the Redis server. It can be useful for many purposes as it makes easy to detect if the instance we are talking about is the same, or if it is a different one or was rebooted. An application of run_id will be in the partial synchronization of replication, where a slave may request a partial sync from a given offset only if it is talking with the same master. Another application is in failover and monitoring scripts. --- src/redis.c | 4 ++++ src/redis.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/redis.c b/src/redis.c index 01ec0531..acc01b4b 100644 --- a/src/redis.c +++ b/src/redis.c @@ -870,6 +870,8 @@ void createSharedObjects(void) { } void initServerConfig() { + getRandomHexChars(server.runid,REDIS_RUN_ID_SIZE); + server.runid[REDIS_RUN_ID_SIZE] = '\0'; server.arch_bits = (sizeof(long) == 8) ? 64 : 32; server.port = REDIS_SERVERPORT; server.bindaddr = NULL; @@ -1585,6 +1587,7 @@ sds genRedisInfoString(char *section) { "multiplexing_api:%s\r\n" "gcc_version:%d.%d.%d\r\n" "process_id:%ld\r\n" + "run_id:%s\r\n" "tcp_port:%d\r\n" "uptime_in_seconds:%ld\r\n" "uptime_in_days:%ld\r\n" @@ -1600,6 +1603,7 @@ sds genRedisInfoString(char *section) { 0,0,0, #endif (long) getpid(), + server.runid, server.port, uptime, uptime/(3600*24), diff --git a/src/redis.h b/src/redis.h index 3ecedd4c..ee1cef4c 100644 --- a/src/redis.h +++ b/src/redis.h @@ -570,6 +570,7 @@ struct redisServer { char *pidfile; /* PID file path */ int arch_bits; /* 32 or 64 depending on sizeof(long) */ int cronloops; /* Number of times the cron function run */ + char runid[REDIS_RUN_ID_SIZE+1]; /* ID always different at every exec. */ /* Networking */ int port; /* TCP listening port */ char *bindaddr; /* Bind address or NULL */ -- 2.45.2