mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 16:40:50 +00:00
Add DISCARD command to discard queued MULTI commands.
This commit is contained in:
parent
c8c72447f6
commit
18b6cb7643
16
redis.c
16
redis.c
@ -653,6 +653,7 @@ static void zscoreCommand(redisClient *c);
|
||||
static void zremrangebyscoreCommand(redisClient *c);
|
||||
static void multiCommand(redisClient *c);
|
||||
static void execCommand(redisClient *c);
|
||||
static void discardCommand(redisClient *c);
|
||||
static void blpopCommand(redisClient *c);
|
||||
static void brpopCommand(redisClient *c);
|
||||
static void appendCommand(redisClient *c);
|
||||
@ -733,6 +734,7 @@ static struct redisCommand cmdTable[] = {
|
||||
{"type",typeCommand,2,REDIS_CMD_INLINE,1,1,1},
|
||||
{"multi",multiCommand,1,REDIS_CMD_INLINE,0,0,0},
|
||||
{"exec",execCommand,1,REDIS_CMD_INLINE,0,0,0},
|
||||
{"discard",discardCommand,1,REDIS_CMD_INLINE,0,0,0},
|
||||
{"sync",syncCommand,1,REDIS_CMD_INLINE,0,0,0},
|
||||
{"flushdb",flushdbCommand,1,REDIS_CMD_INLINE,0,0,0},
|
||||
{"flushall",flushallCommand,1,REDIS_CMD_INLINE,0,0,0},
|
||||
@ -2141,7 +2143,7 @@ static int processCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
/* Exec the command */
|
||||
if (c->flags & REDIS_MULTI && cmd->proc != execCommand) {
|
||||
if (c->flags & REDIS_MULTI && cmd->proc != execCommand && cmd->proc != discardCommand) {
|
||||
queueMultiCommand(c,cmd);
|
||||
addReply(c,shared.queued);
|
||||
} else {
|
||||
@ -6051,6 +6053,18 @@ static void multiCommand(redisClient *c) {
|
||||
addReply(c,shared.ok);
|
||||
}
|
||||
|
||||
static void discardCommand(redisClient *c) {
|
||||
if (!(c->flags & REDIS_MULTI)) {
|
||||
addReplySds(c,sdsnew("-ERR DISCARD without MULTI\r\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
freeClientMultiState(c);
|
||||
initClientMultiState(c);
|
||||
c->flags &= (~REDIS_MULTI);
|
||||
addReply(c,shared.ok);
|
||||
}
|
||||
|
||||
static void execCommand(redisClient *c) {
|
||||
int j;
|
||||
robj **orig_argv;
|
||||
|
@ -1663,6 +1663,18 @@ proc main {server port} {
|
||||
list $v1 $v2 $v3
|
||||
} {QUEUED QUEUED {{a b c} PONG}}
|
||||
|
||||
test {DISCARD} {
|
||||
$r del mylist
|
||||
$r rpush mylist a
|
||||
$r rpush mylist b
|
||||
$r rpush mylist c
|
||||
$r multi
|
||||
set v1 [$r del mylist]
|
||||
set v2 [$r discard]
|
||||
set v3 [$r lrange mylist 0 -1]
|
||||
list $v1 $v2 $v3
|
||||
} {QUEUED OK {a b c}}
|
||||
|
||||
test {APPEND basics} {
|
||||
list [$r append foo bar] [$r get foo] \
|
||||
[$r append foo 100] [$r get foo]
|
||||
|
Loading…
x
Reference in New Issue
Block a user