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
ad08d059
Commit
ad08d059
authored
Feb 28, 2012
by
antirez
Browse files
Added command propagation API.
parent
64ef44d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/redis.c
View file @
ad08d059
...
@@ -1175,10 +1175,33 @@ struct redisCommand *lookupCommandByCString(char *s) {
...
@@ -1175,10 +1175,33 @@ struct redisCommand *lookupCommandByCString(char *s) {
return
cmd
;
return
cmd
;
}
}
/* Propagate the specified command (in the context of the specified database id)
* to AOF, Slaves and Monitors.
*
* flags are an xor between:
* + REDIS_PROPAGATE_NONE (no propagation of command at all)
* + REDIS_PROPAGATE_AOF (propagate into the AOF file if is enabled)
* + REDIS_PROPAGATE_REPL (propagate into the replication link)
*/
void
propagate
(
struct
redisCommand
*
cmd
,
int
dbid
,
robj
**
argv
,
int
argc
,
int
flags
)
{
if
(
server
.
aof_state
!=
REDIS_AOF_OFF
&&
flags
&
REDIS_PROPAGATE_AOF
)
feedAppendOnlyFile
(
cmd
,
dbid
,
argv
,
argc
);
if
(
flags
&
REDIS_PROPAGATE_REPL
&&
listLength
(
server
.
slaves
))
replicationFeedSlaves
(
server
.
slaves
,
dbid
,
argv
,
argc
);
}
/* Call() is the core of Redis execution of a command */
/* Call() is the core of Redis execution of a command */
void
call
(
redisClient
*
c
,
int
flags
)
{
void
call
(
redisClient
*
c
,
int
flags
)
{
long
long
dirty
,
start
=
ustime
(),
duration
;
long
long
dirty
,
start
=
ustime
(),
duration
;
/* Sent the command to clients in MONITOR mode, only if the commands are
* not geneated from reading an AOF. */
if
(
listLength
(
server
.
monitors
)
&&
!
server
.
loading
)
replicationFeedMonitors
(
server
.
monitors
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
);
/* Call the command. */
dirty
=
server
.
dirty
;
dirty
=
server
.
dirty
;
c
->
cmd
->
proc
(
c
);
c
->
cmd
->
proc
(
c
);
dirty
=
server
.
dirty
-
dirty
;
dirty
=
server
.
dirty
-
dirty
;
...
@@ -1189,20 +1212,25 @@ void call(redisClient *c, int flags) {
...
@@ -1189,20 +1212,25 @@ void call(redisClient *c, int flags) {
if
(
server
.
loading
&&
c
->
flags
&
REDIS_LUA_CLIENT
)
if
(
server
.
loading
&&
c
->
flags
&
REDIS_LUA_CLIENT
)
flags
&=
~
(
REDIS_CALL_SLOWLOG
|
REDIS_CALL_STATS
);
flags
&=
~
(
REDIS_CALL_SLOWLOG
|
REDIS_CALL_STATS
);
/* Log the command into the Slow log if needed, and populate the
* per-command statistics that we show in INFO commandstats. */
if
(
flags
&
REDIS_CALL_SLOWLOG
)
if
(
flags
&
REDIS_CALL_SLOWLOG
)
slowlogPushEntryIfNeeded
(
c
->
argv
,
c
->
argc
,
duration
);
slowlogPushEntryIfNeeded
(
c
->
argv
,
c
->
argc
,
duration
);
if
(
flags
&
REDIS_CALL_STATS
)
{
if
(
flags
&
REDIS_CALL_STATS
)
{
c
->
cmd
->
microseconds
+=
duration
;
c
->
cmd
->
microseconds
+=
duration
;
c
->
cmd
->
calls
++
;
c
->
cmd
->
calls
++
;
}
}
/* Propagate the command into the AOF and replication link */
if
(
flags
&
REDIS_CALL_PROPAGATE
)
{
if
(
flags
&
REDIS_CALL_PROPAGATE
)
{
if
(
server
.
aof_state
!=
REDIS_AOF_OFF
&&
dirty
>
0
)
int
flags
=
REDIS_PROPAGATE_NONE
;
feedAppendOnlyFile
(
c
->
cmd
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
);
if
((
dirty
>
0
||
c
->
cmd
->
flags
&
REDIS_CMD_FORCE_REPLICATION
)
&&
if
(
c
->
cmd
->
flags
&
REDIS_CMD_FORCE_REPLICATION
)
listLength
(
server
.
slaves
))
flags
|=
REDIS_PROPAGATE_REPL
;
replicationFeedSlaves
(
server
.
slaves
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
);
if
(
dirty
)
if
(
listLength
(
server
.
monitors
))
flags
|=
(
REDIS_PROPAGATE_REPL
|
REDIS_PROPAGATE_AOF
);
replicationFeedMonitors
(
server
.
monitors
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
);
if
(
flags
!=
REDIS_PROPAGATE_NONE
)
propagate
(
c
->
cmd
,
c
->
db
->
id
,
c
->
argv
,
c
->
argc
,
flags
);
}
}
server
.
stat_numcommands
++
;
server
.
stat_numcommands
++
;
}
}
...
...
src/redis.h
View file @
ad08d059
...
@@ -245,6 +245,11 @@
...
@@ -245,6 +245,11 @@
#define REDIS_CALL_PROPAGATE 4
#define REDIS_CALL_PROPAGATE 4
#define REDIS_CALL_FULL (REDIS_CALL_SLOWLOG | REDIS_CALL_STATS | REDIS_CALL_PROPAGATE)
#define REDIS_CALL_FULL (REDIS_CALL_SLOWLOG | REDIS_CALL_STATS | REDIS_CALL_PROPAGATE)
/* Command propagation flags, see propagate() function */
#define REDIS_PROPAGATE_NONE 0
#define REDIS_PROPAGATE_AOF 1
#define REDIS_PROPAGATE_REPL 2
/* We can print the stacktrace, so our assert is defined this way: */
/* We can print the stacktrace, so our assert is defined this way: */
#define redisAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_redisAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1)))
#define redisAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_redisAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1)))
#define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
#define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
...
...
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