Skip to content

Commit

Permalink
cachedb_redis: fix get() return code for key not found
Browse files Browse the repository at this point in the history
  • Loading branch information
rvlad-patrascu committed Dec 2, 2021
1 parent ddbec15 commit e002e6b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions modules/cachedb_redis/cachedb_redis_dbase.c
Expand Up @@ -546,17 +546,23 @@ int redis_get(cachedb_con *connection,str *attr,str *val)
}

rc = redis_run_command(connection, &reply, attr, "GET %b", attr->s, attr->len);
if (rc != 0) {
if (reply && (reply->type == REDIS_REPLY_NIL || reply->str == NULL
|| reply->len == 0)) {
LM_DBG("no such key - %.*s\n",attr->len,attr->s);
val->s = NULL;
val->len = 0;
freeReplyObject(reply);
return -2;
}

if (rc != 0)
goto out_err;

if (reply->type == REDIS_REPLY_NIL) {
LM_DBG("no such key - %.*s\n",attr->len,attr->s);
val->s = NULL;
val->len = 0;
freeReplyObject(reply);
return -2;
}

if (reply->str == NULL || reply->len == 0) {
/* empty string key */
val->s = NULL;
val->len = 0;
freeReplyObject(reply);
return 0;
}

LM_DBG("GET %.*s - %.*s\n",attr->len,attr->s,(unsigned)reply->len,reply->str);
Expand All @@ -573,7 +579,8 @@ int redis_get(cachedb_con *connection,str *attr,str *val)
return 0;

out_err:
freeReplyObject(reply);
if (reply)
freeReplyObject(reply);
return rc;
}

Expand Down

0 comments on commit e002e6b

Please sign in to comment.