]> git.saurik.com Git - redis.git/blobdiff - src/redis.c
Comment improved so that the code goal is more clear. Thx to @agladysh.
[redis.git] / src / redis.c
index d4d91f176f6d833f8771b32368388d60776526a9..276ed796ce5e717b254477d675b508b52bc81be0 100644 (file)
@@ -622,9 +622,10 @@ void updateDictResizePolicy(void) {
  * keys that can be removed from the keyspace. */
 void activeExpireCycle(void) {
     int j;
+    long long start = mstime();
 
     for (j = 0; j < server.dbnum; j++) {
-        int expired;
+        int expired, iteration = 0;
         redisDb *db = server.db+j;
 
         /* Continue to expire if at the end of the cycle more than 25%
@@ -653,6 +654,12 @@ void activeExpireCycle(void) {
                     server.stat_expiredkeys++;
                 }
             }
+            /* We can't block forever here even if there are many keys to
+             * expire. So after a given amount of milliseconds return to the
+             * caller waiting for the other active expire cycle. */
+            iteration++;
+            if ((iteration & 0xff) == 0 && /* Check once every 255 iterations */
+                (mstime()-start) > REDIS_EXPIRELOOKUPS_TIME_LIMIT) return;
         } while (expired > REDIS_EXPIRELOOKUPS_PER_CRON/4);
     }
 }