diff options
author | antirez <antirez@gmail.com> | 2019-12-16 11:18:20 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2019-12-16 11:18:20 +0100 |
commit | aa3f13761f137956f5846d3c01526647c43c0f81 (patch) | |
tree | 37585b62fcc4b41a18a661319997d83d9fece4e5 /src/module.c | |
parent | 096592506ef3f548a4a3484d5829e04749a24a99 (diff) | |
parent | 276a0937539f18085ee0fc9e904e6df692c70eb0 (diff) | |
download | redis-aa3f13761f137956f5846d3c01526647c43c0f81.tar.gz |
Merge branch 'unstable' of github.com:/antirez/redis into unstable
Diffstat (limited to 'src/module.c')
-rw-r--r-- | src/module.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/module.c b/src/module.c index a96691182..5d9a39387 100644 --- a/src/module.c +++ b/src/module.c @@ -7310,22 +7310,30 @@ int RM_GetLFU(RedisModuleKey *key, long long *lfu_freq) { * Unlike RM_ModuleTypeSetValue() which will free the old value, this function * simply swaps the old value with the new value. * - * The function returns the old value, or NULL if any of the above conditions is - * not met. + * The function returns REDISMODULE_OK on success, REDISMODULE_ERR on errors + * such as: + * + * 1. Key is not opened for writing. + * 2. Key is not a module data type key. + * 3. Key is a module datatype other than 'mt'. + * + * If old_value is non-NULL, the old value is returned by reference. */ -void *RM_ModuleTypeReplaceValue(RedisModuleKey *key, moduleType *mt, void *new_value) { +int RM_ModuleTypeReplaceValue(RedisModuleKey *key, moduleType *mt, void *new_value, void **old_value) { if (!(key->mode & REDISMODULE_WRITE) || key->iter) - return NULL; + return REDISMODULE_ERR; if (!key->value || key->value->type != OBJ_MODULE) - return NULL; + return REDISMODULE_ERR; moduleValue *mv = key->value->ptr; if (mv->type != mt) - return NULL; + return REDISMODULE_ERR; - void *old_val = mv->value; + if (old_value) + *old_value = mv->value; mv->value = new_value; - return old_val; + + return REDISMODULE_OK; } /* Register all the APIs we export. Keep this function at the end of the |