"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/t_zset.c" between
redis-6.2.4.tar.gz and redis-6.2.5.tar.gz

About: redis is an advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

t_zset.c  (redis-6.2.4):t_zset.c  (redis-6.2.5)
skipping to change at line 3662 skipping to change at line 3662
if (opt_withscores || store) { if (opt_withscores || store) {
zrangeResultHandlerScoreEmissionEnable(handler); zrangeResultHandlerScoreEmissionEnable(handler);
} }
/* Step 3: Lookup the key and get the range. */ /* Step 3: Lookup the key and get the range. */
zobj = handler->dstkey ? zobj = handler->dstkey ?
lookupKeyWrite(c->db,key) : lookupKeyWrite(c->db,key) :
lookupKeyRead(c->db,key); lookupKeyRead(c->db,key);
if (zobj == NULL) { if (zobj == NULL) {
addReply(c,shared.emptyarray); if (store) {
handler->beginResultEmission(handler);
handler->finalizeResultEmission(handler, 0);
} else {
addReply(c, shared.emptyarray);
}
goto cleanup; goto cleanup;
} }
if (checkType(c,zobj,OBJ_ZSET)) goto cleanup; if (checkType(c,zobj,OBJ_ZSET)) goto cleanup;
/* Step 4: Pass this to the command-specific handler. */ /* Step 4: Pass this to the command-specific handler. */
switch (rangetype) { switch (rangetype) {
case ZRANGE_AUTO: case ZRANGE_AUTO:
case ZRANGE_RANK: case ZRANGE_RANK:
genericZrangebyrankCommand(handler, zobj, opt_start, opt_end, genericZrangebyrankCommand(handler, zobj, opt_start, opt_end,
skipping to change at line 3819 skipping to change at line 3824
break; break;
} }
/* No candidate for zpopping, return empty. */ /* No candidate for zpopping, return empty. */
if (!zobj) { if (!zobj) {
addReply(c,shared.emptyarray); addReply(c,shared.emptyarray);
return; return;
} }
void *arraylen_ptr = addReplyDeferredLen(c); void *arraylen_ptr = addReplyDeferredLen(c);
long arraylen = 0; long result_count = 0;
/* We emit the key only for the blocking variant. */ /* We emit the key only for the blocking variant. */
if (emitkey) addReplyBulk(c,key); if (emitkey) addReplyBulk(c,key);
/* Respond with a single (flat) array in RESP2 or if countarg is not
* provided (returning a single element). In RESP3, when countarg is
* provided, use nested array. */
int use_nested_array = c->resp > 2 && countarg != NULL;
/* Remove the element. */ /* Remove the element. */
do { do {
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) { if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
unsigned char *zl = zobj->ptr; unsigned char *zl = zobj->ptr;
unsigned char *eptr, *sptr; unsigned char *eptr, *sptr;
unsigned char *vstr; unsigned char *vstr;
unsigned int vlen; unsigned int vlen;
long long vlong; long long vlong;
/* Get the first or last element in the sorted set. */ /* Get the first or last element in the sorted set. */
skipping to change at line 3866 skipping to change at line 3876
serverAssertWithInfo(c,zobj,zln != NULL); serverAssertWithInfo(c,zobj,zln != NULL);
ele = sdsdup(zln->ele); ele = sdsdup(zln->ele);
score = zln->score; score = zln->score;
} else { } else {
serverPanic("Unknown sorted set encoding"); serverPanic("Unknown sorted set encoding");
} }
serverAssertWithInfo(c,zobj,zsetDel(zobj,ele)); serverAssertWithInfo(c,zobj,zsetDel(zobj,ele));
server.dirty++; server.dirty++;
if (arraylen == 0) { /* Do this only for the first iteration. */ if (result_count == 0) { /* Do this only for the first iteration. */
char *events[2] = {"zpopmin","zpopmax"}; char *events[2] = {"zpopmin","zpopmax"};
notifyKeyspaceEvent(NOTIFY_ZSET,events[where],key,c->db->id); notifyKeyspaceEvent(NOTIFY_ZSET,events[where],key,c->db->id);
signalModifiedKey(c,c->db,key); signalModifiedKey(c,c->db,key);
} }
if (use_nested_array) {
addReplyArrayLen(c,2);
}
addReplyBulkCBuffer(c,ele,sdslen(ele)); addReplyBulkCBuffer(c,ele,sdslen(ele));
addReplyDouble(c,score); addReplyDouble(c,score);
sdsfree(ele); sdsfree(ele);
arraylen += 2; ++result_count;
/* Remove the key, if indeed needed. */ /* Remove the key, if indeed needed. */
if (zsetLength(zobj) == 0) { if (zsetLength(zobj) == 0) {
dbDelete(c->db,key); dbDelete(c->db,key);
notifyKeyspaceEvent(NOTIFY_GENERIC,"del",key,c->db->id); notifyKeyspaceEvent(NOTIFY_GENERIC,"del",key,c->db->id);
break; break;
} }
} while(--count); } while(--count);
setDeferredArrayLen(c,arraylen_ptr,arraylen + (emitkey != 0)); if (!use_nested_array) {
result_count *= 2;
}
setDeferredArrayLen(c,arraylen_ptr,result_count + (emitkey != 0));
} }
/* ZPOPMIN key [<count>] */ /* ZPOPMIN key [<count>] */
void zpopminCommand(client *c) { void zpopminCommand(client *c) {
if (c->argc > 3) { if (c->argc > 3) {
addReplyErrorObject(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
genericZpopCommand(c,&c->argv[1],1,ZSET_MIN,0, genericZpopCommand(c,&c->argv[1],1,ZSET_MIN,0,
c->argc == 3 ? c->argv[2] : NULL); c->argc == 3 ? c->argv[2] : NULL);
skipping to change at line 3986 skipping to change at line 4002
/* If client is trying to ask for a very large number of random elements, /* If client is trying to ask for a very large number of random elements,
* queuing may consume an unlimited amount of memory, so we want to limit * queuing may consume an unlimited amount of memory, so we want to limit
* the number of randoms per time. */ * the number of randoms per time. */
#define ZRANDMEMBER_RANDOM_SAMPLE_LIMIT 1000 #define ZRANDMEMBER_RANDOM_SAMPLE_LIMIT 1000
void zrandmemberWithCountCommand(client *c, long l, int withscores) { void zrandmemberWithCountCommand(client *c, long l, int withscores) {
unsigned long count, size; unsigned long count, size;
int uniq = 1; int uniq = 1;
robj *zsetobj; robj *zsetobj;
if ((zsetobj = lookupKeyReadOrReply(c, c->argv[1], shared.null[c->resp])) if ((zsetobj = lookupKeyReadOrReply(c, c->argv[1], shared.emptyarray))
== NULL || checkType(c, zsetobj, OBJ_ZSET)) return; == NULL || checkType(c, zsetobj, OBJ_ZSET)) return;
size = zsetLength(zsetobj); size = zsetLength(zsetobj);
if(l >= 0) { if(l >= 0) {
count = (unsigned long) l; count = (unsigned long) l;
} else { } else {
count = -l; count = -l;
uniq = 0; uniq = 0;
} }
skipping to change at line 4022 skipping to change at line 4038
addReplyArrayLen(c, count); addReplyArrayLen(c, count);
if (zsetobj->encoding == OBJ_ENCODING_SKIPLIST) { if (zsetobj->encoding == OBJ_ENCODING_SKIPLIST) {
zset *zs = zsetobj->ptr; zset *zs = zsetobj->ptr;
while (count--) { while (count--) {
dictEntry *de = dictGetFairRandomKey(zs->dict); dictEntry *de = dictGetFairRandomKey(zs->dict);
sds key = dictGetKey(de); sds key = dictGetKey(de);
if (withscores && c->resp > 2) if (withscores && c->resp > 2)
addReplyArrayLen(c,2); addReplyArrayLen(c,2);
addReplyBulkCBuffer(c, key, sdslen(key)); addReplyBulkCBuffer(c, key, sdslen(key));
if (withscores) if (withscores)
addReplyDouble(c, dictGetDoubleVal(de)); addReplyDouble(c, *(double*)dictGetVal(de));
} }
} else if (zsetobj->encoding == OBJ_ENCODING_ZIPLIST) { } else if (zsetobj->encoding == OBJ_ENCODING_ZIPLIST) {
ziplistEntry *keys, *vals = NULL; ziplistEntry *keys, *vals = NULL;
unsigned long limit, sample_count; unsigned long limit, sample_count;
limit = count > ZRANDMEMBER_RANDOM_SAMPLE_LIMIT ? ZRANDMEMBER_RANDOM _SAMPLE_LIMIT : count; limit = count > ZRANDMEMBER_RANDOM_SAMPLE_LIMIT ? ZRANDMEMBER_RANDOM _SAMPLE_LIMIT : count;
keys = zmalloc(sizeof(ziplistEntry)*limit); keys = zmalloc(sizeof(ziplistEntry)*limit);
if (withscores) if (withscores)
vals = zmalloc(sizeof(ziplistEntry)*limit); vals = zmalloc(sizeof(ziplistEntry)*limit);
while (count) { while (count) {
sample_count = count > limit ? limit : count; sample_count = count > limit ? limit : count;
skipping to change at line 4171 skipping to change at line 4187
zsetReplyFromZiplistEntry(c, &key); zsetReplyFromZiplistEntry(c, &key);
if (withscores) if (withscores)
addReplyDouble(c, score); addReplyDouble(c, score);
} }
/* Release memory */ /* Release memory */
dictRelease(d); dictRelease(d);
} }
} }
/* ZRANDMEMBER [<count> WITHSCORES] */ /* ZRANDMEMBER key [<count> [WITHSCORES]] */
void zrandmemberCommand(client *c) { void zrandmemberCommand(client *c) {
long l; long l;
int withscores = 0; int withscores = 0;
robj *zset; robj *zset;
ziplistEntry ele; ziplistEntry ele;
if (c->argc >= 3) { if (c->argc >= 3) {
if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return; if (getLongFromObjectOrReply(c,c->argv[2],&l,NULL) != C_OK) return;
if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withscor es"))) { if (c->argc > 4 || (c->argc == 4 && strcasecmp(c->argv[3]->ptr,"withscor es"))) {
addReplyErrorObject(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
 End of changes. 10 change blocks. 
8 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)