From 1f7d2c1e27a5378c5db438cb9d1a00fc30f1d598 Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Sat, 9 Mar 2013 11:48:54 +0100
Subject: [PATCH] Optimize inner loop of activeExpireCycle() for no-expires
 case.

---
 src/redis.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/redis.c b/src/redis.c
index 423c8c3a8..042ba4bee 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -671,9 +671,13 @@ void activeExpireCycle(void) {
         /* Continue to expire if at the end of the cycle more than 25%
          * of the keys were expired. */
         do {
-            unsigned long num = dictSize(db->expires);
-            unsigned long slots = dictSlots(db->expires);
-            long long now = mstime();
+            unsigned long num, slots;
+            long long now;
+
+            /* If there is nothing to expire try next DB ASAP. */
+            if ((num = dictSize(db->expires)) == 0) break;
+            slots = dictSlots(db->expires);
+            now = mstime();
 
             /* When there are less than 1% filled slots getting random
              * keys is expensive, so stop here waiting for better times...