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
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
incrRefCount(o);
}
decrRefCount(keyobj);
- if (fieldlen) decrRefCount(fieldobj);
+ if (fieldobj) decrRefCount(fieldobj);
return o;
noobj:
/* 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;
}
if (end >= vectorlen) end = vectorlen-1;
- server.sort_dontsort = dontsort;
if (dontsort == 0) {
server.sort_desc = desc;
server.sort_alpha = alpha;