diff options
author | Dvir Volk <dvirsky@gmail.com> | 2016-09-21 12:30:38 +0300 |
---|---|---|
committer | Dvir Volk <dvirsky@gmail.com> | 2016-09-21 12:30:38 +0300 |
commit | a91650fc57077f53eac658d2da452bcf10d14ee6 (patch) | |
tree | 7615cb255f4e5baba3de35ff3737f679b5e8bba5 /src/modules | |
parent | 670586715a19e7aff9b3af793a7a9b334b418752 (diff) | |
download | redis-a91650fc57077f53eac658d2da452bcf10d14ee6.tar.gz |
added RM_CreateStringPrintf
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/testmodule.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/modules/testmodule.c b/src/modules/testmodule.c index a1a42f43b..db809a8e6 100644 --- a/src/modules/testmodule.c +++ b/src/modules/testmodule.c @@ -93,6 +93,25 @@ int TestStringAppendAM(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) return REDISMODULE_OK; } +/* TEST.STRING.PRINTF -- Test string formatting. */ +int TestStringPrintf(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { + RedisModule_AutoMemory(ctx); + if (argc < 3) { + return RedisModule_WrongArity(ctx); + } + RedisModuleString *s = RedisModule_CreateStringPrintf(ctx, + "Got %d args. argv[1]: %s, argv[2]: %s", + argc, + RedisModule_StringPtrLen(argv[1], NULL), + RedisModule_StringPtrLen(argv[2], NULL) + ); + + RedisModule_ReplyWithString(ctx,s); + + return REDISMODULE_OK; +} + + /* ----------------------------- Test framework ----------------------------- */ /* Return 1 if the reply matches the specified string, otherwise log errors @@ -163,6 +182,9 @@ int TestIt(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { T("test.string.append.am",""); if (!TestAssertStringReply(ctx,reply,"foobar",6)) goto fail; + T("test.string.printf", "cc", "foo", "bar"); + if (!TestAssertStringReply(ctx,reply,"Got 3 args. argv[1]: foo, argv[2]: bar",38)) goto fail; + RedisModule_ReplyWithSimpleString(ctx,"ALL TESTS PASSED"); return REDISMODULE_OK; @@ -188,6 +210,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) TestStringAppendAM,"write deny-oom",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; + if (RedisModule_CreateCommand(ctx,"test.string.printf", + TestStringPrintf,"write deny-oom",1,1,1) == REDISMODULE_ERR) + return REDISMODULE_ERR; + if (RedisModule_CreateCommand(ctx,"test.it", TestIt,"readonly",1,1,1) == REDISMODULE_ERR) return REDISMODULE_ERR; |