Modules Cluster API: GetClusterSize() added.

This commit is contained in:
antirez 2018-04-01 16:36:32 +02:00
parent 27f9c8108c
commit c75582889a
2 changed files with 13 additions and 1 deletions

View File

@ -3968,6 +3968,15 @@ const char *RM_GetMyClusterID(void) {
return server.cluster->myself->name; 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', /* 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 * then returns REDISMODULE_OK. Otherwise if the node ID does not exist from
* the POV of this local node, REDISMODULE_ERR is returned. * the POV of this local node, REDISMODULE_ERR is returned.
@ -4565,4 +4574,5 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(StopTimer); REGISTER_API(StopTimer);
REGISTER_API(GetTimerInfo); REGISTER_API(GetTimerInfo);
REGISTER_API(GetMyClusterID); REGISTER_API(GetMyClusterID);
REGISTER_API(GetClusterSize);
} }

View File

@ -276,7 +276,8 @@ void REDISMODULE_API_FUNC(RedisModule_FreeClusterNodesList)(char **ids);
RedisModuleTimerID REDISMODULE_API_FUNC(RedisModule_CreateTimer)(RedisModuleCtx *ctx, mstime_t period, RedisModuleTimerProc callback, void *data); RedisModuleTimerID REDISMODULE_API_FUNC(RedisModule_CreateTimer)(RedisModuleCtx *ctx, mstime_t period, RedisModuleTimerProc callback, void *data);
int REDISMODULE_API_FUNC(RedisModule_StopTimer)(RedisModuleCtx *ctx, RedisModuleTimerID id, void **data); int REDISMODULE_API_FUNC(RedisModule_StopTimer)(RedisModuleCtx *ctx, RedisModuleTimerID id, void **data);
int REDISMODULE_API_FUNC(RedisModule_GetTimerInfo)(RedisModuleCtx *ctx, RedisModuleTimerID id, uint64_t *remaining, void **data); int REDISMODULE_API_FUNC(RedisModule_GetTimerInfo)(RedisModuleCtx *ctx, RedisModuleTimerID id, uint64_t *remaining, void **data);
const char *REDISMODULE_API_FUNC(RM_GetMyClusterID)(void); const char *REDISMODULE_API_FUNC(RedisModule_GetMyClusterID)(void);
size_t REDISMODULE_API_FUNC(RedisModule_GetClusterSize)(void);
/* Experimental APIs */ /* Experimental APIs */
#ifdef REDISMODULE_EXPERIMENTAL_API #ifdef REDISMODULE_EXPERIMENTAL_API
@ -409,6 +410,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(StopTimer); REDISMODULE_GET_API(StopTimer);
REDISMODULE_GET_API(GetTimerInfo); REDISMODULE_GET_API(GetTimerInfo);
REDISMODULE_GET_API(GetMyClusterID); REDISMODULE_GET_API(GetMyClusterID);
REDISMODULE_GET_API(GetClusterSize);
#ifdef REDISMODULE_EXPERIMENTAL_API #ifdef REDISMODULE_EXPERIMENTAL_API
REDISMODULE_GET_API(GetThreadSafeContext); REDISMODULE_GET_API(GetThreadSafeContext);