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
97f6e314
Commit
97f6e314
authored
Oct 17, 2019
by
antirez
Browse files
Modules: allow to check for AOF loading client.
parent
8651e6a1
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/aof.c
View file @
97f6e314
...
@@ -652,10 +652,11 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a
...
@@ -652,10 +652,11 @@ void feedAppendOnlyFile(struct redisCommand *cmd, int dictid, robj **argv, int a
/* In Redis commands are always executed in the context of a client, so in
/* In Redis commands are always executed in the context of a client, so in
* order to load the append only file we need to create a fake client. */
* order to load the append only file we need to create a fake client. */
struct
client
*
create
Fake
Client
(
void
)
{
struct
client
*
create
AOF
Client
(
void
)
{
struct
client
*
c
=
zmalloc
(
sizeof
(
*
c
));
struct
client
*
c
=
zmalloc
(
sizeof
(
*
c
));
selectDb
(
c
,
0
);
selectDb
(
c
,
0
);
c
->
id
=
CLIENT_ID_AOF
;
/* So modules can identify it's the AOF client. */
c
->
conn
=
NULL
;
c
->
conn
=
NULL
;
c
->
name
=
NULL
;
c
->
name
=
NULL
;
c
->
querybuf
=
sdsempty
();
c
->
querybuf
=
sdsempty
();
...
@@ -729,7 +730,7 @@ int loadAppendOnlyFile(char *filename) {
...
@@ -729,7 +730,7 @@ int loadAppendOnlyFile(char *filename) {
* to the same file we're about to read. */
* to the same file we're about to read. */
server
.
aof_state
=
AOF_OFF
;
server
.
aof_state
=
AOF_OFF
;
fakeClient
=
create
Fake
Client
();
fakeClient
=
create
AOF
Client
();
startLoadingFile
(
fp
,
filename
);
startLoadingFile
(
fp
,
filename
);
/* Check if this AOF file has an RDB preamble. In that case we need to
/* Check if this AOF file has an RDB preamble. In that case we need to
...
...
src/module.c
View file @
97f6e314
...
@@ -1504,7 +1504,15 @@ int RM_ReplicateVerbatim(RedisModuleCtx *ctx) {
...
@@ -1504,7 +1504,15 @@ int RM_ReplicateVerbatim(RedisModuleCtx *ctx) {
* are guaranteed to get IDs greater than any past ID previously seen.
* 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
* 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. */
* to fetch the ID in the context the function was currently called.
*
* After obtaining the ID, it is possible to check if the command execution
* is actually happening in the context of AOF loading, using this macro:
*
* if (RedisModule_IsAOFClient(RedisModule_GetClientId(ctx)) {
* // Handle it differently.
* }
*/
unsigned
long
long
RM_GetClientId
(
RedisModuleCtx
*
ctx
)
{
unsigned
long
long
RM_GetClientId
(
RedisModuleCtx
*
ctx
)
{
if
(
ctx
->
client
==
NULL
)
return
0
;
if
(
ctx
->
client
==
NULL
)
return
0
;
return
ctx
->
client
->
id
;
return
ctx
->
client
->
id
;
...
...
src/redismodule.h
View file @
97f6e314
...
@@ -404,6 +404,8 @@ int REDISMODULE_API_FUNC(RedisModule_ExitFromChild)(int retcode);
...
@@ -404,6 +404,8 @@ int REDISMODULE_API_FUNC(RedisModule_ExitFromChild)(int retcode);
int
REDISMODULE_API_FUNC
(
RedisModule_KillForkChild
)(
int
child_pid
);
int
REDISMODULE_API_FUNC
(
RedisModule_KillForkChild
)(
int
child_pid
);
#endif
#endif
#define RedisModule_IsAOFClient(id) ((id) == UINT64_MAX)
/* 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
)
__attribute__
((
unused
));
static
int
RedisModule_Init
(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
int
ver
,
int
apiver
)
__attribute__
((
unused
));
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
)
{
...
...
src/server.h
View file @
97f6e314
...
@@ -827,6 +827,11 @@ typedef struct user {
...
@@ -827,6 +827,11 @@ typedef struct user {
/* With multiplexing we need to take per-client state.
/* With multiplexing we need to take per-client state.
* Clients are taken in a linked list. */
* Clients are taken in a linked list. */
#define CLIENT_ID_AOF (UINT64_MAX)
/* Reserved ID for the AOF client. If you
need more reserved IDs use UINT64_MAX-1,
-2, ... and so forth. */
typedef
struct
client
{
typedef
struct
client
{
uint64_t
id
;
/* Client incremental unique ID. */
uint64_t
id
;
/* Client incremental unique ID. */
connection
*
conn
;
connection
*
conn
;
...
...
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