Skip to content

Commit 340435d

Browse files
author
DvirDukhan
authored
Merge branch 'master' into fix_memory_leaks
2 parents 43afeb6 + 8243e8d commit 340435d

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

src/command_parser.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ static int _ModelRunCommand_ParseArgs(RedisModuleCtx *ctx, RedisModuleString **a
3030
size_t argpos = 1;
3131
RedisModuleKey *modelKey;
3232
const int status =
33-
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ);
33+
RAI_GetModelFromKeyspace(ctx, argv[argpos], &modelKey, model, REDISMODULE_READ, error);
3434
if (status == REDISMODULE_ERR) {
35-
RAI_SetError(error, RAI_EMODELRUN, "ERR Model not found");
3635
return REDISMODULE_ERR;
3736
}
3837
RAI_HoldString(NULL, argv[argpos]);

src/model.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,22 @@
2020
#include "util/string_utils.h"
2121
#include <pthread.h>
2222
#include "DAG/dag.h"
23+
#include "err.h"
2324

2425
/* Return REDISMODULE_ERR if there was an error getting the Model.
2526
* Return REDISMODULE_OK if the model value stored at key was correctly
2627
* returned and available at *model variable. */
2728
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
28-
RAI_Model **model, int mode) {
29+
RAI_Model **model, int mode, RAI_Error *error) {
2930
*key = RedisModule_OpenKey(ctx, keyName, mode);
3031
if (RedisModule_KeyType(*key) == REDISMODULE_KEYTYPE_EMPTY) {
3132
RedisModule_CloseKey(*key);
32-
RedisModule_ReplyWithError(ctx, "ERR model key is empty");
33+
RAI_SetError(error, REDISMODULE_KEYTYPE_EMPTY, "ERR model key is empty");
3334
return REDISMODULE_ERR;
3435
}
3536
if (RedisModule_ModuleTypeGetType(*key) != RedisAI_ModelType) {
3637
RedisModule_CloseKey(*key);
37-
RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
38+
RAI_SetError(error, REDISMODULE_ERR, REDISMODULE_ERRORMSG_WRONGTYPE);
3839
return REDISMODULE_ERR;
3940
}
4041
*model = RedisModule_ModuleTypeGetValue(*key);

src/model.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,13 @@ int RAI_ModelSerialize(RAI_Model *model, char **buffer, size_t *len, RAI_Error *
116116
* a Redis key with the requested access mode
117117
* @param model destination model structure
118118
* @param mode key access mode
119+
* @param error contains the error in case of problem with retrival
119120
* @return REDISMODULE_OK if the model value stored at key was correctly
120121
* returned and available at *model variable, or REDISMODULE_ERR if there was
121122
* an error getting the Model
122123
*/
123124
int RAI_GetModelFromKeyspace(RedisModuleCtx *ctx, RedisModuleString *keyName, RedisModuleKey **key,
124-
RAI_Model **model, int mode);
125+
RAI_Model **model, int mode, RAI_Error *error);
125126

126127
/**
127128
* When a module command is called in order to obtain the position of

src/redisai.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,11 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
412412

413413
RAI_Model *mto;
414414
RedisModuleKey *key;
415-
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ);
415+
RAI_Error err = {0};
416+
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ, &err);
416417
if (status == REDISMODULE_ERR) {
418+
RedisModule_ReplyWithError(ctx, err.detail);
419+
RAI_ClearError(&err);
417420
return REDISMODULE_ERR;
418421
}
419422

@@ -432,7 +435,6 @@ int RedisAI_ModelGet_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
432435
return RedisModule_ReplyWithError(ctx, "ERR no META or BLOB specified");
433436
}
434437

435-
RAI_Error err = {0};
436438
char *buffer = NULL;
437439
size_t len = 0;
438440

@@ -510,11 +512,14 @@ int RedisAI_ModelDel_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
510512
if (argc != 2)
511513
return RedisModule_WrongArity(ctx);
512514

515+
RAI_Error err = {0};
513516
RAI_Model *mto;
514517
RedisModuleKey *key;
515-
const int status =
516-
RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto, REDISMODULE_READ | REDISMODULE_WRITE);
518+
const int status = RAI_GetModelFromKeyspace(ctx, argv[1], &key, &mto,
519+
REDISMODULE_READ | REDISMODULE_WRITE, &err);
517520
if (status == REDISMODULE_ERR) {
521+
RedisModule_ReplyWithError(ctx, err.detail);
522+
RAI_ClearError(&err);
518523
return REDISMODULE_ERR;
519524
}
520525

0 commit comments

Comments
 (0)