mirror of
https://github.com/fluencelabs/redis
synced 2025-03-17 16:10:50 +00:00
Convert objects in the command procs instead of the protocol code
This commit is contained in:
parent
b19c33d48a
commit
75b41de8ca
@ -266,9 +266,6 @@ int loadAppendOnlyFile(char *filename) {
|
||||
redisLog(REDIS_WARNING,"Unknown command '%s' reading the append only file", argv[0]->ptr);
|
||||
exit(1);
|
||||
}
|
||||
/* Try object encoding */
|
||||
if (cmd->flags & REDIS_CMD_BULK)
|
||||
argv[argc-1] = tryObjectEncoding(argv[argc-1]);
|
||||
/* Run the command in the context of a fake client */
|
||||
fakeClient->argc = argc;
|
||||
fakeClient->argv = argv;
|
||||
|
@ -410,6 +410,7 @@ void configGetCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
void configCommand(redisClient *c) {
|
||||
c->argv[c->argc-1] = tryObjectEncoding(c->argv[c->argc-1]);
|
||||
if (!strcasecmp(c->argv[1]->ptr,"set")) {
|
||||
if (c->argc != 4) goto badarity;
|
||||
configSetCommand(c);
|
||||
|
@ -262,6 +262,7 @@ void punsubscribeCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
void publishCommand(redisClient *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
int receivers = pubsubPublishMessage(c->argv[1],c->argv[2]);
|
||||
addReplyLongLong(c,receivers);
|
||||
}
|
||||
|
@ -914,10 +914,6 @@ int processCommand(redisClient *c) {
|
||||
return REDIS_OK;
|
||||
}
|
||||
|
||||
/* Let's try to encode the bulk object to save space. */
|
||||
if (cmd->flags & REDIS_CMD_BULK)
|
||||
c->argv[c->argc-1] = tryObjectEncoding(c->argv[c->argc-1]);
|
||||
|
||||
/* Check if the user is authenticated */
|
||||
if (server.requirepass && !c->authenticated && cmd->proc != authCommand) {
|
||||
addReplyError(c,"operation not permitted");
|
||||
@ -1011,6 +1007,7 @@ void pingCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
void echoCommand(redisClient *c) {
|
||||
c->argv[1] = tryObjectEncoding(c->argv[1]);
|
||||
addReplyBulk(c,c->argv[1]);
|
||||
}
|
||||
|
||||
|
@ -220,6 +220,7 @@ void hsetCommand(redisClient *c) {
|
||||
robj *o;
|
||||
|
||||
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
|
||||
c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
hashTypeTryConversion(o,c->argv,2,3);
|
||||
hashTypeTryObjectEncoding(o,&c->argv[2], &c->argv[3]);
|
||||
update = hashTypeSet(o,c->argv[2],c->argv[3]);
|
||||
@ -231,6 +232,7 @@ void hsetCommand(redisClient *c) {
|
||||
void hsetnxCommand(redisClient *c) {
|
||||
robj *o;
|
||||
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
|
||||
c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
hashTypeTryConversion(o,c->argv,2,3);
|
||||
|
||||
if (hashTypeExists(o, c->argv[2])) {
|
||||
@ -254,6 +256,7 @@ void hmsetCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
if ((o = hashTypeLookupWriteOrCreate(c,c->argv[1])) == NULL) return;
|
||||
c->argv[c->argc-1] = tryObjectEncoding(c->argv[c->argc-1]);
|
||||
hashTypeTryConversion(o,c->argv,2,c->argc-1);
|
||||
for (i = 2; i < c->argc; i += 2) {
|
||||
hashTypeTryObjectEncoding(o,&c->argv[i], &c->argv[i+1]);
|
||||
@ -296,6 +299,7 @@ void hgetCommand(redisClient *c) {
|
||||
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
|
||||
checkType(c,o,REDIS_HASH)) return;
|
||||
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if ((value = hashTypeGet(o,c->argv[2])) != NULL) {
|
||||
addReplyBulk(c,value);
|
||||
decrRefCount(value);
|
||||
@ -316,6 +320,7 @@ void hmgetCommand(redisClient *c) {
|
||||
* done because objects that cannot be found are considered to be
|
||||
* an empty hash. The reply should then be a series of NULLs. */
|
||||
addReplyMultiBulkLen(c,c->argc-2);
|
||||
c->argv[c->argc-1] = tryObjectEncoding(c->argv[c->argc-1]);
|
||||
for (i = 2; i < c->argc; i++) {
|
||||
if (o != NULL && (value = hashTypeGet(o,c->argv[i])) != NULL) {
|
||||
addReplyBulk(c,value);
|
||||
@ -331,6 +336,7 @@ void hdelCommand(redisClient *c) {
|
||||
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||
checkType(c,o,REDIS_HASH)) return;
|
||||
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if (hashTypeDelete(o,c->argv[2])) {
|
||||
if (hashTypeLength(o) == 0) dbDelete(c->db,c->argv[1]);
|
||||
addReply(c,shared.cone);
|
||||
@ -395,5 +401,6 @@ void hexistsCommand(redisClient *c) {
|
||||
if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||
checkType(c,o,REDIS_HASH)) return;
|
||||
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
addReply(c, hashTypeExists(o,c->argv[2]) ? shared.cone : shared.czero);
|
||||
}
|
||||
|
@ -260,6 +260,7 @@ void listTypeConvert(robj *subject, int enc) {
|
||||
|
||||
void pushGenericCommand(redisClient *c, int where) {
|
||||
robj *lobj = lookupKeyWrite(c->db,c->argv[1]);
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if (lobj == NULL) {
|
||||
if (handleClientsWaitingListPush(c,c->argv[1],c->argv[2])) {
|
||||
addReply(c,shared.cone);
|
||||
@ -346,14 +347,17 @@ void pushxGenericCommand(redisClient *c, robj *refval, robj *val, int where) {
|
||||
}
|
||||
|
||||
void lpushxCommand(redisClient *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
pushxGenericCommand(c,NULL,c->argv[2],REDIS_HEAD);
|
||||
}
|
||||
|
||||
void rpushxCommand(redisClient *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
pushxGenericCommand(c,NULL,c->argv[2],REDIS_TAIL);
|
||||
}
|
||||
|
||||
void linsertCommand(redisClient *c) {
|
||||
c->argv[4] = tryObjectEncoding(c->argv[4]);
|
||||
if (strcasecmp(c->argv[2]->ptr,"after") == 0) {
|
||||
pushxGenericCommand(c,c->argv[3],c->argv[4],REDIS_TAIL);
|
||||
} else if (strcasecmp(c->argv[2]->ptr,"before") == 0) {
|
||||
@ -409,7 +413,7 @@ void lsetCommand(redisClient *c) {
|
||||
robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);
|
||||
if (o == NULL || checkType(c,o,REDIS_LIST)) return;
|
||||
int index = atoi(c->argv[2]->ptr);
|
||||
robj *value = c->argv[3];
|
||||
robj *value = (c->argv[3] = tryObjectEncoding(c->argv[3]));
|
||||
|
||||
listTypeTryConversion(o,value);
|
||||
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
|
||||
@ -559,7 +563,8 @@ void ltrimCommand(redisClient *c) {
|
||||
}
|
||||
|
||||
void lremCommand(redisClient *c) {
|
||||
robj *subject, *obj = c->argv[3];
|
||||
robj *subject, *obj;
|
||||
obj = c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
int toremove = atoi(c->argv[2]->ptr);
|
||||
int removed = 0;
|
||||
listTypeEntry entry;
|
||||
|
@ -178,6 +178,7 @@ void saddCommand(redisClient *c) {
|
||||
robj *set;
|
||||
|
||||
set = lookupKeyWrite(c->db,c->argv[1]);
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if (set == NULL) {
|
||||
set = setTypeCreate(c->argv[2]);
|
||||
dbAdd(c->db,c->argv[1],set);
|
||||
@ -202,6 +203,7 @@ void sremCommand(redisClient *c) {
|
||||
if ((set = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||
checkType(c,set,REDIS_SET)) return;
|
||||
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if (setTypeRemove(set,c->argv[2])) {
|
||||
if (setTypeSize(set) == 0) dbDelete(c->db,c->argv[1]);
|
||||
touchWatchedKey(c->db,c->argv[1]);
|
||||
@ -216,7 +218,7 @@ void smoveCommand(redisClient *c) {
|
||||
robj *srcset, *dstset, *ele;
|
||||
srcset = lookupKeyWrite(c->db,c->argv[1]);
|
||||
dstset = lookupKeyWrite(c->db,c->argv[2]);
|
||||
ele = c->argv[3];
|
||||
ele = c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
|
||||
/* If the source key does not exist return 0 */
|
||||
if (srcset == NULL) {
|
||||
@ -264,6 +266,7 @@ void sismemberCommand(redisClient *c) {
|
||||
if ((set = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||
checkType(c,set,REDIS_SET)) return;
|
||||
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if (setTypeIsMember(set,c->argv[2]))
|
||||
addReply(c,shared.cone);
|
||||
else
|
||||
|
@ -37,14 +37,17 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir
|
||||
}
|
||||
|
||||
void setCommand(redisClient *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
setGenericCommand(c,0,c->argv[1],c->argv[2],NULL);
|
||||
}
|
||||
|
||||
void setnxCommand(redisClient *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
setGenericCommand(c,1,c->argv[1],c->argv[2],NULL);
|
||||
}
|
||||
|
||||
void setexCommand(redisClient *c) {
|
||||
c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
setGenericCommand(c,0,c->argv[1],c->argv[3],c->argv[2]);
|
||||
}
|
||||
|
||||
@ -69,6 +72,7 @@ void getCommand(redisClient *c) {
|
||||
|
||||
void getsetCommand(redisClient *c) {
|
||||
if (getGenericCommand(c) == REDIS_ERR) return;
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
dbReplace(c->db,c->argv[1],c->argv[2]);
|
||||
incrRefCount(c->argv[2]);
|
||||
touchWatchedKey(c->db,c->argv[1]);
|
||||
@ -180,6 +184,7 @@ void appendCommand(redisClient *c) {
|
||||
robj *o;
|
||||
|
||||
o = lookupKeyWrite(c->db,c->argv[1]);
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
if (o == NULL) {
|
||||
/* Create the key */
|
||||
retval = dbAdd(c->db,c->argv[1],c->argv[2]);
|
||||
|
@ -392,12 +392,14 @@ void zaddGenericCommand(redisClient *c, robj *key, robj *ele, double score, int
|
||||
void zaddCommand(redisClient *c) {
|
||||
double scoreval;
|
||||
if (getDoubleFromObjectOrReply(c,c->argv[2],&scoreval,NULL) != REDIS_OK) return;
|
||||
c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
zaddGenericCommand(c,c->argv[1],c->argv[3],scoreval,0);
|
||||
}
|
||||
|
||||
void zincrbyCommand(redisClient *c) {
|
||||
double scoreval;
|
||||
if (getDoubleFromObjectOrReply(c,c->argv[2],&scoreval,NULL) != REDIS_OK) return;
|
||||
c->argv[3] = tryObjectEncoding(c->argv[3]);
|
||||
zaddGenericCommand(c,c->argv[1],c->argv[3],scoreval,1);
|
||||
}
|
||||
|
||||
@ -412,6 +414,7 @@ void zremCommand(redisClient *c) {
|
||||
checkType(c,zsetobj,REDIS_ZSET)) return;
|
||||
|
||||
zs = zsetobj->ptr;
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
de = dictFind(zs->dict,c->argv[2]);
|
||||
if (de == NULL) {
|
||||
addReply(c,shared.czero);
|
||||
@ -921,6 +924,7 @@ void zscoreCommand(redisClient *c) {
|
||||
checkType(c,o,REDIS_ZSET)) return;
|
||||
|
||||
zs = o->ptr;
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
de = dictFind(zs->dict,c->argv[2]);
|
||||
if (!de) {
|
||||
addReply(c,shared.nullbulk);
|
||||
@ -944,6 +948,7 @@ void zrankGenericCommand(redisClient *c, int reverse) {
|
||||
|
||||
zs = o->ptr;
|
||||
zsl = zs->zsl;
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
de = dictFind(zs->dict,c->argv[2]);
|
||||
if (!de) {
|
||||
addReply(c,shared.nullbulk);
|
||||
|
Loading…
x
Reference in New Issue
Block a user