Format fixes and naming. SentReplyOnKeyMiss -> addReplyOrErrorObject (#9346)

Following the comments on #8659, this PR fix some formatting
and naming issues.
This commit is contained in:
Meir Shpilraien (Spielrein) 2021-08-10 10:19:21 +03:00 committed by GitHub
parent 02fd76b97c
commit 8f8117f78e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 13 deletions

View File

@ -165,24 +165,16 @@ robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags) {
robj *lookupKeyWrite(redisDb *db, robj *key) { robj *lookupKeyWrite(redisDb *db, robj *key) {
return lookupKeyWriteWithFlags(db, key, LOOKUP_NONE); return lookupKeyWriteWithFlags(db, key, LOOKUP_NONE);
} }
void SentReplyOnKeyMiss(client *c, robj *reply){
serverAssert(sdsEncodedObject(reply));
sds rep = reply->ptr;
if (sdslen(rep) > 1 && rep[0] == '-'){
addReplyErrorObject(c, reply);
} else {
addReply(c,reply);
}
}
robj *lookupKeyReadOrReply(client *c, robj *key, robj *reply) { robj *lookupKeyReadOrReply(client *c, robj *key, robj *reply) {
robj *o = lookupKeyRead(c->db, key); robj *o = lookupKeyRead(c->db, key);
if (!o) SentReplyOnKeyMiss(c, reply); if (!o) addReplyOrErrorObject(c, reply);
return o; return o;
} }
robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) { robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) {
robj *o = lookupKeyWrite(c->db, key); robj *o = lookupKeyWrite(c->db, key);
if (!o) SentReplyOnKeyMiss(c, reply); if (!o) addReplyOrErrorObject(c, reply);
return o; return o;
} }

View File

@ -469,6 +469,21 @@ void addReplyErrorObject(client *c, robj *err) {
afterErrorReply(c, err->ptr, sdslen(err->ptr)-2); /* Ignore trailing \r\n */ afterErrorReply(c, err->ptr, sdslen(err->ptr)-2); /* Ignore trailing \r\n */
} }
/* Sends either a reply or an error reply by checking the first char.
 * If the first char is '-' the reply is considered an error.
 * In any case the given reply is sent, if the reply is also recognize
* as an error we also perform some post reply operations such as
* logging and stats update. */
void addReplyOrErrorObject(client *c, robj *reply) {
serverAssert(sdsEncodedObject(reply));
sds rep = reply->ptr;
if (sdslen(rep) > 1 && rep[0] == '-') {
addReplyErrorObject(c, reply);
} else {
addReply(c, reply);
}
}
/* See addReplyErrorLength for expectations from the input string. */ /* See addReplyErrorLength for expectations from the input string. */
void addReplyError(client *c, const char *err) { void addReplyError(client *c, const char *err) {
addReplyErrorLength(c,err,strlen(err)); addReplyErrorLength(c,err,strlen(err));

View File

@ -1403,7 +1403,7 @@ robj *objectCommandLookup(client *c, robj *key) {
robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply) { robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply) {
robj *o = objectCommandLookup(c,key); robj *o = objectCommandLookup(c,key);
if (!o) SentReplyOnKeyMiss(c, reply); if (!o) addReplyOrErrorObject(c, reply);
return o; return o;
} }

View File

@ -1891,6 +1891,7 @@ void addReplySds(client *c, sds s);
void addReplyBulkSds(client *c, sds s); void addReplyBulkSds(client *c, sds s);
void setDeferredReplyBulkSds(client *c, void *node, sds s); void setDeferredReplyBulkSds(client *c, void *node, sds s);
void addReplyErrorObject(client *c, robj *err); void addReplyErrorObject(client *c, robj *err);
void addReplyOrErrorObject(client *c, robj *reply);
void addReplyErrorSds(client *c, sds err); void addReplyErrorSds(client *c, sds err);
void addReplyError(client *c, const char *err); void addReplyError(client *c, const char *err);
void addReplyStatus(client *c, const char *status); void addReplyStatus(client *c, const char *status);
@ -2396,7 +2397,6 @@ robj *lookupKeyReadWithFlags(redisDb *db, robj *key, int flags);
robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags); robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags);
robj *objectCommandLookup(client *c, robj *key); robj *objectCommandLookup(client *c, robj *key);
robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply); robj *objectCommandLookupOrReply(client *c, robj *key, robj *reply);
void SentReplyOnKeyMiss(client *c, robj *reply);
int objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle, int objectSetLRUOrLFU(robj *val, long long lfu_freq, long long lru_idle,
long long lru_clock, int lru_multiplier); long long lru_clock, int lru_multiplier);
#define LOOKUP_NONE 0 #define LOOKUP_NONE 0