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
ecdbc333
Commit
ecdbc333
authored
Sep 28, 2015
by
antirez
Browse files
FLUSHDB and FLUSHALL ASYNC option implemented.
parent
1f26a946
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
ecdbc333
...
...
@@ -247,7 +247,7 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
* DB number if we want to flush only a single Redis database number.
*
* Flags are be EMPTYDB_NO_FLAGS if no special flags are specified or
* EMPTYDB_ASY
C
N if we want the memory to be freed in a different thread
* EMPTYDB_ASYN
C
if we want the memory to be freed in a different thread
* and the function to return ASAP.
*
* On success the fuction returns the number of keys removed from the
...
...
@@ -310,18 +310,49 @@ void signalFlushedDb(int dbid) {
* Type agnostic commands operating on the key space
*----------------------------------------------------------------------------*/
/* Return the set of flags to use for the emptyDb() call for FLUSHALL
* and FLUSHDB commands.
*
* Currently the command just attempts to parse the "ASYNC" option. It
* also checks if the command arity is wrong.
*
* On success C_OK is returned and the flags are stored in *flags, otherwise
* C_ERR is returned and the function sends an error to the client. */
int
getFlushCommandFlags
(
client
*
c
,
int
*
flags
)
{
/* Parse the optional ASYNC option. */
if
(
c
->
argc
>
1
)
{
if
(
c
->
argc
>
2
||
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"async"
))
{
addReply
(
c
,
shared
.
syntaxerr
);
return
C_ERR
;
}
*
flags
=
EMPTYDB_ASYNC
;
}
else
{
*
flags
=
EMPTYDB_NO_FLAGS
;
}
return
C_OK
;
}
/* FLUSHDB [ASYNC]
*
* Flushes the currently SELECTed Redis DB. */
void
flushdbCommand
(
client
*
c
)
{
server
.
dirty
+=
dictSize
(
c
->
db
->
dict
);
int
flags
;
if
(
getFlushCommandFlags
(
c
,
&
flags
)
==
C_ERR
)
return
;
signalFlushedDb
(
c
->
db
->
id
);
dictEmpty
(
c
->
db
->
dict
,
NULL
);
dictEmpty
(
c
->
db
->
expires
,
NULL
);
if
(
server
.
cluster_enabled
)
slotToKeyFlush
();
server
.
dirty
+=
emptyDb
(
c
->
db
->
id
,
flags
,
NULL
);
addReply
(
c
,
shared
.
ok
);
}
/* FLUSHALL [ASYNC]
*
* Flushes the whole server data set. */
void
flushallCommand
(
client
*
c
)
{
int
flags
;
if
(
getFlushCommandFlags
(
c
,
&
flags
)
==
C_ERR
)
return
;
signalFlushedDb
(
-
1
);
server
.
dirty
+=
emptyDb
(
-
1
,
EMPTYDB_NO_FLAGS
,
NULL
);
server
.
dirty
+=
emptyDb
(
-
1
,
flags
,
NULL
);
addReply
(
c
,
shared
.
ok
);
if
(
server
.
rdb_child_pid
!=
-
1
)
{
kill
(
server
.
rdb_child_pid
,
SIGUSR1
);
...
...
src/server.c
View file @
ecdbc333
...
...
@@ -242,8 +242,8 @@ struct redisCommand redisCommandTable[] = {
{
"sync"
,
syncCommand
,
1
,
"ars"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"psync"
,
syncCommand
,
3
,
"ars"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"replconf"
,
replconfCommand
,
-
1
,
"arslt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushdb"
,
flushdbCommand
,
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushall"
,
flushallCommand
,
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushdb"
,
flushdbCommand
,
-
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"flushall"
,
flushallCommand
,
-
1
,
"w"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"sort"
,
sortCommand
,
-
2
,
"wm"
,
0
,
sortGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"info"
,
infoCommand
,
-
1
,
"rlt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"monitor"
,
monitorCommand
,
1
,
"ars"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
...
...
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