Merge pull request #4852 from soloestoy/optimize-flushall

optimize flushdb, avoid useless loops
This commit is contained in:
Salvatore Sanfilippo 2018-07-25 16:30:11 +02:00 committed by GitHub
commit fe408ad23f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -329,7 +329,7 @@ robj *dbUnshareStringValue(redisDb *db, robj *key, robj *o) {
* database(s). Otherwise -1 is returned in the specific case the
* DB number is out of range, and errno is set to EINVAL. */
long long emptyDb(int dbnum, int flags, void(callback)(void*)) {
int j, async = (flags & EMPTYDB_ASYNC);
int async = (flags & EMPTYDB_ASYNC);
long long removed = 0;
if (dbnum < -1 || dbnum >= server.dbnum) {
@ -337,7 +337,10 @@ long long emptyDb(int dbnum, int flags, void(callback)(void*)) {
return -1;
}
for (j = 0; j < server.dbnum; j++) {
int j = dbnum == -1 ? 0 : dbnum;
int dbmax = dbnum == -1 ? server.dbnum : dbnum+1;
for (; j < dbmax; j++) {
if (dbnum != -1 && dbnum != j) continue;
removed += dictSize(server.db[j].dict);
if (async) {