]> git.saurik.com Git - redis.git/commitdiff
Merge git://github.com/tmm1/redis
authorantirez <antirez@gmail.com>
Wed, 20 May 2009 08:42:43 +0000 (10:42 +0200)
committerantirez <antirez@gmail.com>
Wed, 20 May 2009 08:42:43 +0000 (10:42 +0200)
1  2 
redis.c

diff --combined redis.c
index 12d211ab50e23ae8922b02a7a0d20d22e5c2fea2,f4e15bb42f915bf726dd2013ce2d8e615b222348..fbd1bc3df1807678cc297dcdc8ec3958f4061c84
+++ b/redis.c
@@@ -56,8 -56,7 +56,8 @@@
  #include "dict.h"   /* Hash tables */
  #include "adlist.h" /* Linked lists */
  #include "zmalloc.h" /* total memory usage aware version of malloc/free */
 -#include "lzf.h"
 +#include "lzf.h"    /* LZF compression library */
 +#include "pqsort.h" /* Partial qsort for SORT+LIMIT */
  
  /* Error codes */
  #define REDIS_OK                0
@@@ -721,7 -720,7 +721,7 @@@ int serverCron(struct aeEventLoop *even
      }
  
      /* Close connections of timedout clients */
-     if (!(loops % 10))
+     if (server.maxidletime && !(loops % 10))
          closeTimedoutClients();
  
      /* Check if a background saving in progress terminated */
@@@ -960,7 -959,7 +960,7 @@@ static void loadServerConfig(char *file
          /* Execute config directives */
          if (!strcasecmp(argv[0],"timeout") && argc == 2) {
              server.maxidletime = atoi(argv[1]);
-             if (server.maxidletime < 1) {
+             if (server.maxidletime < 0) {
                  err = "Invalid timeout value"; goto loaderr;
              }
          } else if (!strcasecmp(argv[0],"port") && argc == 2) {
@@@ -3014,9 -3013,6 +3014,6 @@@ static void sinterGenericCommand(redisC
          /* If we have a target key where to store the resulting set
           * create this key with an empty set inside */
          dstset = createSetObject();
-         deleteKey(c->db,dstkey);
-         dictAdd(c->db->dict,dstkey,dstset);
-         incrRefCount(dstkey);
      }
  
      /* Iterate all the elements of the first (smallest) set, and test
      }
      dictReleaseIterator(di);
  
+     if (dstkey) {
+         /* Store the resulting set into the target */
+         deleteKey(c->db,dstkey);
+         dictAdd(c->db->dict,dstkey,dstset);
+         incrRefCount(dstkey);
+     }
      if (!dstkey) {
          lenobj->ptr = sdscatprintf(sdsempty(),"*%d\r\n",cardinality);
      } else {
@@@ -3096,23 -3099,10 +3100,10 @@@ static void sunionDiffGenericCommand(re
       * this set object will be the resulting object to set into the target key*/
      dstset = createSetObject();
  
-     /* The first thing we should output is the total number of elements...
-      * since this is a multi-bulk write, but at this stage we don't know
-      * the intersection set size, so we use a trick, append an empty object
-      * to the output list and save the pointer to later modify it with the
-      * right length */
-     if (dstkey) {
-         /* If we have a target key where to store the resulting set
-          * create this key with an empty set inside */
-         deleteKey(c->db,dstkey);
-         dictAdd(c->db->dict,dstkey,dstset);
-         incrRefCount(dstkey);
-         server.dirty++;
-     }
      /* Iterate all the elements of all the sets, add every element a single
       * time to the result set */
      for (j = 0; j < setsnum; j++) {
+         if (op == REDIS_OP_DIFF && j == 0 && !dv[j]) break; /* result set is empty */
          if (!dv[j]) continue; /* non existing keys are like empty sets */
  
          di = dictGetIterator(dv[j]);
              }
          }
          dictReleaseIterator(di);
+         if (op == REDIS_OP_DIFF && cardinality == 0) break; /* result set is empty */
      }
  
      /* Output the content of the resulting set, if not in STORE mode */
              addReply(c,shared.crlf);
          }
          dictReleaseIterator(di);
+     } else {
+         /* If we have a target key where to store the resulting set
+          * create this key with the result set inside */
+         deleteKey(c->db,dstkey);
+         dictAdd(c->db->dict,dstkey,dstset);
+         incrRefCount(dstkey);
+         server.dirty++;
      }
  
      /* Cleanup */
@@@ -3427,10 -3426,7 +3427,10 @@@ static void sortCommand(redisClient *c
          server.sort_desc = desc;
          server.sort_alpha = alpha;
          server.sort_bypattern = sortby ? 1 : 0;
 -        qsort(vector,vectorlen,sizeof(redisSortObject),sortCompare);
 +        if (sortby && (start != 0 || end != vectorlen-1))
 +            pqsort(vector,vectorlen,sizeof(redisSortObject),sortCompare, start,end);
 +        else
 +            qsort(vector,vectorlen,sizeof(redisSortObject),sortCompare);
      }
  
      /* Send command output to the output buffer, performing the specified