X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/3c25c4a691aec646cfdc3f840f356ef3bb5840c0..4b1f6ad3e7a5c7c28618e43e7539c9a937bf8521:/src/sort.c diff --git a/src/sort.c b/src/sort.c index ff655c7e..e5178cd0 100644 --- a/src/sort.c +++ b/src/sort.c @@ -28,7 +28,7 @@ redisSortOperation *createSortOperation(int type, robj *pattern) { robj *lookupKeyByPattern(redisDb *db, robj *pattern, robj *subst) { char *p, *f, *k; sds spat, ssub; - robj *keyobj, *fieldobj, *o; + robj *keyobj, *fieldobj = NULL, *o; int prefixlen, sublen, postfixlen, fieldlen; /* If the pattern is "#" return the substitution object itself in order @@ -76,7 +76,7 @@ robj *lookupKeyByPattern(redisDb *db, robj *pattern, robj *subst) { o = lookupKeyRead(db,keyobj); if (o == NULL) goto noobj; - if (fieldlen > 0) { + if (fieldobj) { if (o->type != REDIS_HASH) goto noobj; /* Retrieve value from hash by the field name. This operation @@ -90,7 +90,7 @@ robj *lookupKeyByPattern(redisDb *db, robj *pattern, robj *subst) { incrRefCount(o); } decrRefCount(keyobj); - if (fieldlen) decrRefCount(fieldobj); + if (fieldobj) decrRefCount(fieldobj); return o; noobj: @@ -215,8 +215,11 @@ void sortCommand(redisClient *c) { /* If we have STORE we need to force sorting for deterministic output * and replication. We use alpha sorting since this is guaranteed to - * work with any input. */ - if (storekey && dontsort) { + * work with any input. + * + * We also want determinism when SORT is called from Lua scripts, so + * in this case we also force alpha sorting. */ + if ((storekey || c->flags & REDIS_LUA_CLIENT) && dontsort) { dontsort = 0; alpha = 1; sortby = NULL; @@ -326,7 +329,6 @@ void sortCommand(redisClient *c) { } if (end >= vectorlen) end = vectorlen-1; - server.sort_dontsort = dontsort; if (dontsort == 0) { server.sort_desc = desc; server.sort_alpha = alpha;