]> git.saurik.com Git - redis.git/commitdiff
load key from swap on key lookup
authorantirez <antirez@gmail.com>
Tue, 5 Jan 2010 12:28:06 +0000 (07:28 -0500)
committerantirez <antirez@gmail.com>
Tue, 5 Jan 2010 12:28:06 +0000 (07:28 -0500)
redis.c

diff --git a/redis.c b/redis.c
index 8d1b91d3d4a5cf67350ce86e6ed26630d3936cdf..1b93c58cd5b3c8cb96862b586defd5a5d7fe77dc 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -488,6 +488,7 @@ static void unblockClient(redisClient *c);
 static int handleClientsWaitingListPush(redisClient *c, robj *key, robj *ele);
 static void vmInit(void);
 static void vmMarkPagesFree(off_t page, off_t count);
+static robj *vmLoadObject(robj *key);
 
 static void authCommand(redisClient *c);
 static void pingCommand(redisClient *c);
@@ -2359,11 +2360,21 @@ static void decrRefCount(void *obj) {
 static robj *lookupKey(redisDb *db, robj *key) {
     dictEntry *de = dictFind(db->dict,key);
     if (de) {
-        robj *o = dictGetEntryVal(de);
+        robj *key = dictGetEntryKey(de);
+        robj *val = dictGetEntryVal(de);
 
-        /* Update the access time of the key for the aging algorithm. */
-        if (server.vm_enabled) o->vm.atime = server.unixtime;
-        return o;
+        if (server.vm_enabled) {
+            if (key->storage == REDIS_VM_MEMORY) {
+                /* Update the access time of the key for the aging algorithm. */
+                key->vm.atime = server.unixtime;
+            } else {
+                /* Our value was swapped on disk. Bring it at home. */
+                assert(val == NULL);
+                val = vmLoadObject(key);
+                dictGetEntryVal(de) = val;
+            }
+        }
+        return val;
     } else {
         return NULL;
     }