diff --git a/inventory_provider/tasks/common.py b/inventory_provider/tasks/common.py
index df62f1f8fe8faf3b3f1faceda53bcd107dce90d7..1ded6cfeecd82d7a37eeab4230320a4f2f6b0c8e 100644
--- a/inventory_provider/tasks/common.py
+++ b/inventory_provider/tasks/common.py
@@ -131,7 +131,7 @@ def get_next_redis(config):
         next_id = latch['next']
     else:
         db_ids = sorted(set(config['redis-databases']))
-        next_id = db_ids[0] if len(db_ids) == 1 else db_ids[1]
+        next_id = db_ids[1 % len(db_ids)]
         logger.debug(
             'get_next_redis[3], next db not configured, '
             'derived next id: {}'.format(next_id))
diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py
index 1c075b3fcd5d1d5a339c1e8a820ab90fa49d41fa..0cd6fcdb1cc02ccf22b16628be7090f658621eaa 100644
--- a/inventory_provider/tasks/worker.py
+++ b/inventory_provider/tasks/worker.py
@@ -12,7 +12,8 @@ from lxml import etree
 import jsonschema
 
 from inventory_provider.tasks.app import app
-from inventory_provider.tasks.common import get_next_redis, latch_db
+from inventory_provider.tasks.common \
+    import get_next_redis, latch_db, get_latch, set_latch
 from inventory_provider import config
 from inventory_provider import environment
 from inventory_provider.db import db, opsdb
@@ -438,6 +439,16 @@ def _derive_router_hostnames(config):
     return junosspace_equipment & opsdb_equipment
 
 
+def _erase_next_db(config):
+    r = get_next_redis(config)
+    saved_latch = get_latch(r)
+    r.flushdb()
+    if saved_latch:
+        set_latch(
+            config,
+            new_current=saved_latch['current'],
+            new_next=saved_latch['next'])
+
 def launch_refresh_cache_all(config):
     """
     utility function intended to be called outside of the worker process
@@ -446,8 +457,7 @@ def launch_refresh_cache_all(config):
     """
     logger = logging.getLogger(__name__)
 
-    r = get_next_redis(config)
-    r.flushdb()
+    _erase_next_db(config)
 
     # first batch of subtasks: refresh cached opsdb data
     subtasks = [