From 95360c2e0cb65956bfcd2c57fb909a9c93723e21 Mon Sep 17 00:00:00 2001 From: "Meir Shpilraien (Spielrein)" Date: Tue, 16 Mar 2021 14:49:59 +0200 Subject: [PATCH] Fix issue where error replies are not counted on stats (#8659) lookupKeyReadOrReply and lookupKeyWriteOrReply might decide to reply to the user with the given robj reply. This reply might be an error reply and if so addReply function is used instead of addReplyErrorObject which will cause the error reply not to be counted on stats. The fix checks the first char in the reply and if its '-' (error) it uses addReplyErrorObject. --- src/db.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index 2660ad876..27af0a53e 100644 --- a/src/db.c +++ b/src/db.c @@ -164,16 +164,24 @@ robj *lookupKeyWriteWithFlags(redisDb *db, robj *key, int flags) { robj *lookupKeyWrite(redisDb *db, robj *key) { return lookupKeyWriteWithFlags(db, key, LOOKUP_NONE); } - +static 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 *o = lookupKeyRead(c->db, key); - if (!o) addReply(c,reply); + if (!o) SentReplyOnKeyMiss(c, reply); return o; } robj *lookupKeyWriteOrReply(client *c, robj *key, robj *reply) { robj *o = lookupKeyWrite(c->db, key); - if (!o) addReply(c,reply); + if (!o) SentReplyOnKeyMiss(c, reply); return o; }