mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
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.
This commit is contained in:
parent
c65b75e740
commit
3a2ff55617
@ -1615,6 +1615,23 @@ void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Use CLIENT SETNAME to name the connection in the Redis instance as
|
||||||
|
* sentinel-<first_8_chars_of_runid>-<connection_type>
|
||||||
|
* 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
|
/* Create the async connections for the specified instance if the instance
|
||||||
* is disconnected. Note that the SRI_DISCONNECTED flag is set even if just
|
* is disconnected. Note that the SRI_DISCONNECTED flag is set even if just
|
||||||
* one of the two links (commands and pub/sub) is missing. */
|
* one of the two links (commands and pub/sub) is missing. */
|
||||||
@ -1637,6 +1654,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
|
|||||||
redisAsyncSetDisconnectCallback(ri->cc,
|
redisAsyncSetDisconnectCallback(ri->cc,
|
||||||
sentinelDisconnectCallback);
|
sentinelDisconnectCallback);
|
||||||
sentinelSendAuthIfNeeded(ri,ri->cc);
|
sentinelSendAuthIfNeeded(ri,ri->cc);
|
||||||
|
sentinelSetClientName(ri,ri->cc,"cmd");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Pub / Sub */
|
/* Pub / Sub */
|
||||||
@ -1657,6 +1675,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
|
|||||||
redisAsyncSetDisconnectCallback(ri->pc,
|
redisAsyncSetDisconnectCallback(ri->pc,
|
||||||
sentinelDisconnectCallback);
|
sentinelDisconnectCallback);
|
||||||
sentinelSendAuthIfNeeded(ri,ri->pc);
|
sentinelSendAuthIfNeeded(ri,ri->pc);
|
||||||
|
sentinelSetClientName(ri,ri->pc,"pubsub");
|
||||||
/* Now we subscribe to the Sentinels "Hello" channel. */
|
/* Now we subscribe to the Sentinels "Hello" channel. */
|
||||||
retval = redisAsyncCommand(ri->pc,
|
retval = redisAsyncCommand(ri->pc,
|
||||||
sentinelReceiveHelloMessages, NULL, "SUBSCRIBE %s",
|
sentinelReceiveHelloMessages, NULL, "SUBSCRIBE %s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user