summaryrefslogtreecommitdiff
path: root/src/module.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-04-01 16:36:32 +0200
committerantirez <antirez@gmail.com>2018-04-01 16:36:32 +0200
commitc75582889a49ed15524a05f855d2a6327451c8c6 (patch)
tree8503fd5ab21ec32cffdd96aad157b5187809db41 /src/module.c
parent27f9c8108c1c6a803ad8e386d655c7065feda394 (diff)
downloadredis-c75582889a49ed15524a05f855d2a6327451c8c6.tar.gz
Modules Cluster API: GetClusterSize() added.
Diffstat (limited to 'src/module.c')
-rw-r--r--src/module.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c
index 78e6aea49..1aa398849 100644
--- a/src/module.c
+++ b/src/module.c
@@ -3968,6 +3968,15 @@ const char *RM_GetMyClusterID(void) {
return server.cluster->myself->name;
}
+/* Return the number of nodes in the cluster, regardless of their state
+ * (handshake, noaddress, ...) so that the number of active nodes may actually
+ * be smaller, but not greater than this number. If the instance is not in
+ * cluster mode, zero is returned. */
+size_t RM_GetClusterSize(void) {
+ if (!server.cluster_enabled) return 0;
+ return dictSize(server.cluster->nodes);
+}
+
/* Populate the specified info for the node having as ID the specified 'id',
* then returns REDISMODULE_OK. Otherwise if the node ID does not exist from
* the POV of this local node, REDISMODULE_ERR is returned.
@@ -4565,4 +4574,5 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(StopTimer);
REGISTER_API(GetTimerInfo);
REGISTER_API(GetMyClusterID);
+ REGISTER_API(GetClusterSize);
}