Remove all keys from the database(s) structure. The dbarray argument * may not be the server main DBs (could be a backup). * * The dbnum can be -1 if all the DBs should be emptied, or the specified * DB index if we want to empty only a single database. * The function returns the number of keys removed from the database(s). */
| 381 | * DB index if we want to empty only a single database. |
| 382 | * The function returns the number of keys removed from the database(s). */ |
| 383 | long long emptyDbStructure(redisDb *dbarray, int dbnum, int async, |
| 384 | void(callback)(void*)) |
| 385 | { |
| 386 | long long removed = 0; |
| 387 | int startdb, enddb; |
| 388 | |
| 389 | if (dbnum == -1) { |
| 390 | startdb = 0; |
| 391 | enddb = server.dbnum-1; |
| 392 | } else { |
| 393 | startdb = enddb = dbnum; |
| 394 | } |
| 395 | |
| 396 | for (int j = startdb; j <= enddb; j++) { |
| 397 | removed += dictSize(dbarray[j].dict); |
| 398 | if (async) { |
| 399 | emptyDbAsync(&dbarray[j]); |
| 400 | } else { |
| 401 | dictEmpty(dbarray[j].dict,callback); |
| 402 | dictEmpty(dbarray[j].expires,callback); |
| 403 | } |
| 404 | /* Because all keys of database are removed, reset average ttl. */ |
| 405 | dbarray[j].avg_ttl = 0; |
| 406 | dbarray[j].expires_cursor = 0; |
| 407 | } |
| 408 | |
| 409 | return removed; |
| 410 | } |
| 411 | |
| 412 | /* Remove all keys from all the databases in a Redis server. |
| 413 | * If callback is given the function is called from time to time to |
no test coverage detected