diff options
author | antirez <antirez@gmail.com> | 2015-02-09 23:44:42 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2015-02-11 10:52:27 +0100 |
commit | cc7f0434b5c590e5a61c3cefa6ed9fb193d021dd (patch) | |
tree | 81fdf4ddb46382a5c893f35f34185acffd59ecaf /src/redis.c | |
parent | 6b5922dcbbfe5428accc093892ff330211acf5d7 (diff) | |
download | redis-cc7f0434b5c590e5a61c3cefa6ed9fb193d021dd.tar.gz |
Change alsoPropagate() behavior to make it more usable.
Now the API automatically creates its argv copy and increment ref count
of passed objects.
Diffstat (limited to 'src/redis.c')
-rw-r--r-- | src/redis.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/redis.c b/src/redis.c index 277d2e4b0..8bfcfdaad 100644 --- a/src/redis.c +++ b/src/redis.c @@ -2016,11 +2016,28 @@ void propagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, } /* Used inside commands to schedule the propagation of additional commands - * after the current command is propagated to AOF / Replication. */ + * after the current command is propagated to AOF / Replication. + * + * 'cmd' must be a pointer to the Redis command to replicate, dbid is the + * database ID the command should be propagated into. + * Arguments of the command to propagte are passed as an array of redis + * objects pointers of len 'argc', using the 'argv' vector. + * + * The function does not take a reference to the passed 'argv' vector, + * so it is up to the caller to release the passed argv (but it is usually + * stack allocated). The function autoamtically increments ref count of + * passed objects, so the caller does not need to. */ void alsoPropagate(struct redisCommand *cmd, int dbid, robj **argv, int argc, int target) { - redisOpArrayAppend(&server.also_propagate,cmd,dbid,argv,argc,target); + robj **argvcopy = zmalloc(sizeof(robj*)*argc); + int j; + + for (j = 0; j < argc; j++) { + argvcopy[j] = argv[j]; + incrRefCount(argv[j]); + } + redisOpArrayAppend(&server.also_propagate,cmd,dbid,argvcopy,argc,target); } /* It is possible to call the function forceCommandPropagation() inside a |