From 00a29b1a81f75dce175ac2199a7e1e9806a476dc Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 16 Feb 2018 16:18:01 +0100 Subject: [PATCH] Make addReplyError...() family functions able to get error codes. Now you can use: addReplyError("-MYERRORCODE some message"); If the error code is omitted, the behavior is like in the past, the generic -ERR will be used. --- src/networking.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/networking.c b/src/networking.c index c29adc1e..4d30504b 100644 --- a/src/networking.c +++ b/src/networking.c @@ -385,8 +385,18 @@ void addReplyString(client *c, const char *s, size_t len) { _addReplyStringToList(c,s,len); } +/* Low level function called by the addReplyError...() functions. + * It emits the protocol for a Redis error, in the form: + * + * -ERRORCODE Error Message + * + * If the error code is already passed in the string 's', the error + * code provided is used, otherwise the string "-ERR " for the generic + * error code is automatically added. */ void addReplyErrorLength(client *c, const char *s, size_t len) { - addReplyString(c,"-ERR ",5); + /* If the string already starts with "-..." then the error code + * is provided by the caller. Otherwise we use "-ERR". */ + if (!len || s[0] != '-') addReplyString(c,"-ERR ",5); addReplyString(c,s,len); addReplyString(c,"\r\n",2); if (c->flags & CLIENT_MASTER) {