@@ -653,6 +653,7 @@ static void zscoreCommand(redisClient *c);
653
653
static void zremrangebyscoreCommand (redisClient * c );
654
654
static void multiCommand (redisClient * c );
655
655
static void execCommand (redisClient * c );
656
+ static void discardCommand (redisClient * c );
656
657
static void blpopCommand (redisClient * c );
657
658
static void brpopCommand (redisClient * c );
658
659
static void appendCommand (redisClient * c );
@@ -733,6 +734,7 @@ static struct redisCommand cmdTable[] = {
733
734
{"type" ,typeCommand ,2 ,REDIS_CMD_INLINE ,1 ,1 ,1 },
734
735
{"multi" ,multiCommand ,1 ,REDIS_CMD_INLINE ,0 ,0 ,0 },
735
736
{"exec" ,execCommand ,1 ,REDIS_CMD_INLINE ,0 ,0 ,0 },
737
+ {"discard" ,discardCommand ,1 ,REDIS_CMD_INLINE ,0 ,0 ,0 },
736
738
{"sync" ,syncCommand ,1 ,REDIS_CMD_INLINE ,0 ,0 ,0 },
737
739
{"flushdb" ,flushdbCommand ,1 ,REDIS_CMD_INLINE ,0 ,0 ,0 },
738
740
{"flushall" ,flushallCommand ,1 ,REDIS_CMD_INLINE ,0 ,0 ,0 },
@@ -2141,7 +2143,7 @@ static int processCommand(redisClient *c) {
2141
2143
}
2142
2144
2143
2145
/* Exec the command */
2144
- if (c -> flags & REDIS_MULTI && cmd -> proc != execCommand ) {
2146
+ if (c -> flags & REDIS_MULTI && cmd -> proc != execCommand && cmd -> proc != discardCommand ) {
2145
2147
queueMultiCommand (c ,cmd );
2146
2148
addReply (c ,shared .queued );
2147
2149
} else {
@@ -6051,6 +6053,18 @@ static void multiCommand(redisClient *c) {
6051
6053
addReply (c ,shared .ok );
6052
6054
}
6053
6055
6056
+ static void discardCommand (redisClient * c ) {
6057
+ if (!(c -> flags & REDIS_MULTI )) {
6058
+ addReplySds (c ,sdsnew ("-ERR DISCARD without MULTI\r\n" ));
6059
+ return ;
6060
+ }
6061
+
6062
+ freeClientMultiState (c );
6063
+ initClientMultiState (c );
6064
+ c -> flags &= (~REDIS_MULTI );
6065
+ addReply (c ,shared .ok );
6066
+ }
6067
+
6054
6068
static void execCommand (redisClient * c ) {
6055
6069
int j ;
6056
6070
robj * * orig_argv ;
0 commit comments