added GetClientId

master
Dvir Volk 9 years ago
parent 52e51be203
commit 12443ebbde

@ -57,6 +57,8 @@
* [RedisModule_ReplicateVerbatim](#redismodule_replicateverbatim) * [RedisModule_ReplicateVerbatim](#redismodule_replicateverbatim)
* [RedisModule_GetClientId](#redismodule_getclientid)
* [RedisModule_GetSelectedDb](#redismodule_getselecteddb) * [RedisModule_GetSelectedDb](#redismodule_getselecteddb)
* [RedisModule_SelectDb](#redismodule_selectdb) * [RedisModule_SelectDb](#redismodule_selectdb)
@ -562,6 +564,23 @@ int RedisModule_ReplicateVerbatim(RedisModuleCtx *ctx) {
The function always returns REDISMODULE_OK. 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 ### RedisModule_GetSelectedDb
``` ```
int RedisModule_GetSelectedDb(RedisModuleCtx *ctx) { 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 free the vector and the underlying data. Does not release its elements if
they are pointers they are pointers

@ -25,6 +25,7 @@ int ParseCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_ReplyWithLongLong(ctx, x + y); RedisModule_ReplyWithLongLong(ctx, x + y);
return REDISMODULE_OK; return REDISMODULE_OK;
} }
// If we got PROD - return the product of 2 consecutive arguments // If we got PROD - return the product of 2 consecutive arguments
if (RMUtil_ParseArgsAfter("PROD", argv, argc, "ll", &x, &y) == if (RMUtil_ParseArgsAfter("PROD", argv, argc, "ll", &x, &y) ==
REDISMODULE_OK) { REDISMODULE_OK) {

@ -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_HashGet)(RedisModuleKey *key, int flags, ...);
int REDISMODULE_API_FUNC(RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx); int REDISMODULE_API_FUNC(RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx);
void REDISMODULE_API_FUNC(RedisModule_KeyAtPos)(RedisModuleCtx *ctx, int pos); 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. */ /* This is included inline inside each Redis module. */
static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) { 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(HashGet);
REDISMODULE_GET_API(IsKeysPositionRequest); REDISMODULE_GET_API(IsKeysPositionRequest);
REDISMODULE_GET_API(KeyAtPos); REDISMODULE_GET_API(KeyAtPos);
REDISMODULE_GET_API(GetClientId);
RedisModule_SetModuleAttribs(ctx,name,ver,apiver); RedisModule_SetModuleAttribs(ctx,name,ver,apiver);
return REDISMODULE_OK; return REDISMODULE_OK;

Loading…
Cancel
Save