From 3a2ff5561781807ebbe98706953b88ea8ed6fe6d Mon Sep 17 00:00:00 2001 From: antirez Date: Sat, 15 Mar 2014 14:59:23 +0100 Subject: [PATCH] Sentinel: use CLIENT SETNAME when connecting to Redis. This makes debugging / monitoring of Sentinels simpler since you can identify sentinels in CLIENT LIST output of Redis instances. --- src/sentinel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/sentinel.c b/src/sentinel.c index 29a4db00..f6fca47c 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -1615,6 +1615,23 @@ void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) { } } +/* Use CLIENT SETNAME to name the connection in the Redis instance as + * sentinel-- + * The connection type is "cmd" or "pubsub" as specified by 'type'. + * + * This makes it possible to list all the sentinel instances connected + * to a Redis servewr with CLIENT LIST, grepping for a specific name format. */ +void sentinelSetClientName(sentinelRedisInstance *ri, redisAsyncContext *c, char *type) { + char name[64]; + + snprintf(name,sizeof(name),"sentinel-%.8s-%s",server.runid,type); + if (redisAsyncCommand(c, sentinelDiscardReplyCallback, NULL, + "CLIENT SETNAME %s", name) == REDIS_OK) + { + ri->pending_commands++; + } +} + /* Create the async connections for the specified instance if the instance * is disconnected. Note that the SRI_DISCONNECTED flag is set even if just * one of the two links (commands and pub/sub) is missing. */ @@ -1637,6 +1654,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) { redisAsyncSetDisconnectCallback(ri->cc, sentinelDisconnectCallback); sentinelSendAuthIfNeeded(ri,ri->cc); + sentinelSetClientName(ri,ri->cc,"cmd"); } } /* Pub / Sub */ @@ -1657,6 +1675,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) { redisAsyncSetDisconnectCallback(ri->pc, sentinelDisconnectCallback); sentinelSendAuthIfNeeded(ri,ri->pc); + sentinelSetClientName(ri,ri->pc,"pubsub"); /* Now we subscribe to the Sentinels "Hello" channel. */ retval = redisAsyncCommand(ri->pc, sentinelReceiveHelloMessages, NULL, "SUBSCRIBE %s",