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
18b6cb76
Commit
18b6cb76
authored
Feb 27, 2010
by
Damian Janowski
Committed by
antirez
Mar 01, 2010
Browse files
Add DISCARD command to discard queued MULTI commands.
parent
c8c72447
Changes
2
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
18b6cb76
...
@@ -653,6 +653,7 @@ static void zscoreCommand(redisClient *c);
...
@@ -653,6 +653,7 @@ static void zscoreCommand(redisClient *c);
static
void
zremrangebyscoreCommand
(
redisClient
*
c
);
static
void
zremrangebyscoreCommand
(
redisClient
*
c
);
static
void
multiCommand
(
redisClient
*
c
);
static
void
multiCommand
(
redisClient
*
c
);
static
void
execCommand
(
redisClient
*
c
);
static
void
execCommand
(
redisClient
*
c
);
static
void
discardCommand
(
redisClient
*
c
);
static
void
blpopCommand
(
redisClient
*
c
);
static
void
blpopCommand
(
redisClient
*
c
);
static
void
brpopCommand
(
redisClient
*
c
);
static
void
brpopCommand
(
redisClient
*
c
);
static
void
appendCommand
(
redisClient
*
c
);
static
void
appendCommand
(
redisClient
*
c
);
...
@@ -733,6 +734,7 @@ static struct redisCommand cmdTable[] = {
...
@@ -733,6 +734,7 @@ static struct redisCommand cmdTable[] = {
{
"type"
,
typeCommand
,
2
,
REDIS_CMD_INLINE
,
1
,
1
,
1
},
{
"type"
,
typeCommand
,
2
,
REDIS_CMD_INLINE
,
1
,
1
,
1
},
{
"multi"
,
multiCommand
,
1
,
REDIS_CMD_INLINE
,
0
,
0
,
0
},
{
"multi"
,
multiCommand
,
1
,
REDIS_CMD_INLINE
,
0
,
0
,
0
},
{
"exec"
,
execCommand
,
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
},
{
"sync"
,
syncCommand
,
1
,
REDIS_CMD_INLINE
,
0
,
0
,
0
},
{
"flushdb"
,
flushdbCommand
,
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
},
{
"flushall"
,
flushallCommand
,
1
,
REDIS_CMD_INLINE
,
0
,
0
,
0
},
...
@@ -2141,7 +2143,7 @@ static int processCommand(redisClient *c) {
...
@@ -2141,7 +2143,7 @@ static int processCommand(redisClient *c) {
}
}
/* Exec the command */
/* 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
);
queueMultiCommand
(
c
,
cmd
);
addReply
(
c
,
shared
.
queued
);
addReply
(
c
,
shared
.
queued
);
}
else
{
}
else
{
...
@@ -6051,6 +6053,18 @@ static void multiCommand(redisClient *c) {
...
@@ -6051,6 +6053,18 @@ static void multiCommand(redisClient *c) {
addReply
(
c
,
shared
.
ok
);
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
)
{
static
void
execCommand
(
redisClient
*
c
)
{
int
j
;
int
j
;
robj
**
orig_argv
;
robj
**
orig_argv
;
...
...
test-redis.tcl
View file @
18b6cb76
...
@@ -1663,6 +1663,18 @@ proc main {server port} {
...
@@ -1663,6 +1663,18 @@ proc main {server port} {
list $v1 $v2 $v3
list $v1 $v2 $v3
}
{
QUEUED QUEUED
{{
a b c
}
PONG
}}
}
{
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
}
{
test
{
APPEND basics
}
{
list
[
$r
append foo bar
]
[
$r
get foo
]
\
list
[
$r
append foo bar
]
[
$r
get foo
]
\
[
$r
append foo 100
]
[
$r
get foo
]
[
$r
append foo 100
]
[
$r
get foo
]
...
...
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