Skip to content
This repository

proper SORT for zset with iterating skiplist #14

Open
wants to merge 1 commit into from

1 participant

rikarends
rikarends

The SORT command used the dictionary to build up the vector from a ZSET,
but it should use the skiplist instead, elsewise its not possible to create a SORT in the order of the sorted set (which is usually what you want)

Jeremy Fishman jfishman referenced this pull request
Closed

Fix signal handler #213

s-tchaikovsky s-tchaikovsky referenced this pull request
Closed

Redis crush #1221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 06, 2010
* Fixed using the skiplist as the source for SORT for sorted sets, in…
…stead of the dictionary
fde46d1
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 16 additions and 1 deletion. Show diff stats Hide diff stats

  1. 17  src/sort.c
17  src/sort.c
@@ -230,6 +230,8 @@ void sortCommand(redisClient *c) {
230 230
         }
231 231
         setTypeReleaseIterator(si);
232 232
     } else if (sortval->type == REDIS_ZSET) {
  233
+    	// lets do this using the skiplist of a sorted set
  234
+    	/*
233 235
         dict *set = ((zset*)sortval->ptr)->dict;
234 236
         dictIterator *di;
235 237
         dictEntry *setele;
@@ -240,7 +242,20 @@ void sortCommand(redisClient *c) {
240 242
             vector[j].u.cmpobj = NULL;
241 243
             j++;
242 244
         }
243  
-        dictReleaseIterator(di);
  245
+        dictReleaseIterator(di);*/
  246
+    	zset *zsetobj = (zset*)sortval->ptr;
  247
+    	zskiplist *zsl = zsetobj->zsl;
  248
+    	zskiplistNode *ln = zsl->header->forward[0];
  249
+    	int llen = (int) zsl->length;
  250
+		for (j = 0; j < llen; j++) {
  251
+			if(!ln){ redisPanic("NULL in ZSET skiplist while doing SORT"); break;}
  252
+			vector[j].obj = ln->obj;
  253
+			vector[j].u.score = 0;
  254
+			vector[j].u.cmpobj = 0;
  255
+			ln = ln->forward[0];
  256
+		}
  257
+
  258
+
244 259
     } else {
245 260
         redisPanic("Unknown type");
246 261
     }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.