Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6250a6b1
Commit
6250a6b1
authored
May 03, 2016
by
antirez
Browse files
Modules: RM_GetClientId() implemented.
parent
9a71df50
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
6250a6b1
...
@@ -856,6 +856,22 @@ int RM_ReplicateVerbatim(RedisModuleCtx *ctx) {
...
@@ -856,6 +856,22 @@ int RM_ReplicateVerbatim(RedisModuleCtx *ctx) {
* DB and Key APIs -- Generic API
* DB and Key APIs -- Generic API
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
/* 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. */
unsigned
long
long
RM_GetClientId
(
RedisModuleCtx
*
ctx
)
{
if
(
ctx
->
client
==
NULL
)
return
0
;
return
ctx
->
client
->
id
;
}
/* Return the currently selected DB. */
/* Return the currently selected DB. */
int
RM_GetSelectedDb
(
RedisModuleCtx
*
ctx
)
{
int
RM_GetSelectedDb
(
RedisModuleCtx
*
ctx
)
{
return
ctx
->
client
->
db
->
id
;
return
ctx
->
client
->
db
->
id
;
...
@@ -2270,6 +2286,7 @@ void moduleRegisterCoreAPI(void) {
...
@@ -2270,6 +2286,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
HashGet
);
REGISTER_API
(
HashGet
);
REGISTER_API
(
IsKeysPositionRequest
);
REGISTER_API
(
IsKeysPositionRequest
);
REGISTER_API
(
KeyAtPos
);
REGISTER_API
(
KeyAtPos
);
REGISTER_API
(
GetClientId
);
}
}
/* Global initialization at Redis startup. */
/* Global initialization at Redis startup. */
...
...
src/redismodule.h
View file @
6250a6b1
...
@@ -149,6 +149,7 @@ int REDISMODULE_API_FUNC(RedisModule_HashSet)(RedisModuleKey *key, int flags, ..
...
@@ -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
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment