Skip to content

Commit

Permalink
fix code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oranagra committed Jun 22, 2021
1 parent 46618b0 commit f0097eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/module.c
Expand Up @@ -2559,19 +2559,19 @@ int RM_StringTruncate(RedisModuleKey *key, size_t newlen) {
} else {
/* Unshare and resize. */
key->value = dbUnshareStringValue(key->db, key->key, key->value);
if (newlen == 0) {
sdsfree(key->value->ptr);
key->value->ptr = sdsempty();
} else {
size_t curlen = sdslen(key->value->ptr);
if (newlen > curlen) {
if (newlen == 0) {
sdsfree(key->value->ptr);
key->value->ptr = sdsempty();
} else {
size_t curlen = sdslen(key->value->ptr);
if (newlen > curlen) {
key->value->ptr = sdsgrowzero(key->value->ptr,newlen);
} else if (newlen < curlen) {
} else if (newlen < curlen) {
sdsrange(key->value->ptr,0,newlen-1);
/* If the string is too wasteful, reallocate it. */
if (sdslen(key->value->ptr) < sdsavail(key->value->ptr))
key->value->ptr = sdsRemoveFreeSpace(key->value->ptr);
}
key->value->ptr = sdsRemoveFreeSpace(key->value->ptr);
}
}
}
return REDISMODULE_OK;
Expand Down
9 changes: 6 additions & 3 deletions tests/modules/basics.c
Expand Up @@ -425,8 +425,11 @@ int TestAssertIntegerReply(RedisModuleCtx *ctx, RedisModuleCallReply *reply, lon
reply = RedisModule_Call(ctx,name,__VA_ARGS__); \
} while (0)

/* TEST.IT -- Run all the tests. */
int TestIt(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
/* TEST.BASICS -- Run all the tests.
* Note: it is useful to run these tests from the module rather than TCL
* since it's easier to check the reply types like that (make a distinction
* between 0 and "0", etc. */
int TestBasics(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
REDISMODULE_NOT_USED(argv);
REDISMODULE_NOT_USED(argc);

Expand Down Expand Up @@ -509,7 +512,7 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
return REDISMODULE_ERR;

if (RedisModule_CreateCommand(ctx,"test.basics",
TestIt,"readonly",1,1,1) == REDISMODULE_ERR)
TestBasics,"readonly",1,1,1) == REDISMODULE_ERR)
return REDISMODULE_ERR;

RedisModule_SubscribeToKeyspaceEvents(ctx,
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/moduleapi/commandfilter.tcl
Expand Up @@ -81,5 +81,4 @@ start_server {tags {"modules"}} {
assert_equal {} [r lrange log-key 0 -1]
}

r module unload commandfilter
}
}

0 comments on commit f0097eb

Please sign in to comment.