From 12443ebbdea37fe7f0f0d6a43e6473c345ffde1f Mon Sep 17 00:00:00 2001 From: Dvir Volk Date: Tue, 3 May 2016 15:40:17 +0300 Subject: [PATCH] added GetClientId --- FUNCTIONS.md | 20 +++++++++++++++++++- example/module.c | 1 + redismodule.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/FUNCTIONS.md b/FUNCTIONS.md index 69d57b7..11bc9d4 100644 --- a/FUNCTIONS.md +++ b/FUNCTIONS.md @@ -57,6 +57,8 @@ * [RedisModule_ReplicateVerbatim](#redismodule_replicateverbatim) +* [RedisModule_GetClientId](#redismodule_getclientid) + * [RedisModule_GetSelectedDb](#redismodule_getselecteddb) * [RedisModule_SelectDb](#redismodule_selectdb) @@ -562,6 +564,23 @@ int RedisModule_ReplicateVerbatim(RedisModuleCtx *ctx) { The function always returns REDISMODULE_OK. +### RedisModule_GetClientId +``` +unsigned long long RedisModule_GetClientId(RedisModuleCtx *ctx) { +``` + Return the ID of the current client calling the currently active module + command. The returned ID has a few guarantees: + + 1. The ID is different for each different client, so if the same client + executes a module command multiple times, it can be recognized as + having the same ID, otherwise the ID will be different. + 2. The ID increases monotonically. Clients connecting to the server later + are guaranteed to get IDs greater than any past ID previously seen. + + Valid IDs are from 1 to 2^64-1. If 0 is returned it means there is no way + to fetch the ID in the context the function was currently called. + + ### RedisModule_GetSelectedDb ``` int RedisModule_GetSelectedDb(RedisModuleCtx *ctx) { @@ -1242,4 +1261,3 @@ void Vector_Free(Vector *v); free the vector and the underlying data. Does not release its elements if they are pointers - diff --git a/example/module.c b/example/module.c index a3f2525..3ee5efd 100644 --- a/example/module.c +++ b/example/module.c @@ -25,6 +25,7 @@ int ParseCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { RedisModule_ReplyWithLongLong(ctx, x + y); return REDISMODULE_OK; } + // If we got PROD - return the product of 2 consecutive arguments if (RMUtil_ParseArgsAfter("PROD", argv, argc, "ll", &x, &y) == REDISMODULE_OK) { diff --git a/redismodule.h b/redismodule.h index d23f8cb..e54825d 100644 --- a/redismodule.h +++ b/redismodule.h @@ -149,6 +149,7 @@ int REDISMODULE_API_FUNC(RedisModule_HashSet)(RedisModuleKey *key, int flags, .. int REDISMODULE_API_FUNC(RedisModule_HashGet)(RedisModuleKey *key, int flags, ...); int REDISMODULE_API_FUNC(RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx); void REDISMODULE_API_FUNC(RedisModule_KeyAtPos)(RedisModuleCtx *ctx, int pos); +unsigned long long REDISMODULE_API_FUNC(RedisModule_GetClientId)(RedisModuleCtx *ctx); /* This is included inline inside each Redis module. */ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) { @@ -217,6 +218,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int REDISMODULE_GET_API(HashGet); REDISMODULE_GET_API(IsKeysPositionRequest); REDISMODULE_GET_API(KeyAtPos); + REDISMODULE_GET_API(GetClientId); RedisModule_SetModuleAttribs(ctx,name,ver,apiver); return REDISMODULE_OK;