diff options
Diffstat (limited to 'tests/modules')
-rw-r--r-- | tests/modules/reply.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/tests/modules/reply.c b/tests/modules/reply.c index 3835909ad..f890560e0 100644 --- a/tests/modules/reply.c +++ b/tests/modules/reply.c @@ -3,6 +3,7 @@ */ #include "redismodule.h" +#include <math.h> int rw_string(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { if (argc != 2) return RedisModule_WrongArity(ctx); @@ -27,12 +28,22 @@ int rw_int(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { return RedisModule_ReplyWithLongLong(ctx, integer); } +/* When one argument is given, it is returned as a double, + * when two arguments are given, it returns a/b. */ int rw_double(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { - if (argc != 2) return RedisModule_WrongArity(ctx); + if (argc==1) + return RedisModule_ReplyWithDouble(ctx, NAN); + + if (argc != 2 && argc != 3) return RedisModule_WrongArity(ctx); - double dbl; + double dbl, dbl2; if (RedisModule_StringToDouble(argv[1], &dbl) != REDISMODULE_OK) return RedisModule_ReplyWithError(ctx, "Arg cannot be parsed as a double"); + if (argc == 3) { + if (RedisModule_StringToDouble(argv[2], &dbl2) != REDISMODULE_OK) + return RedisModule_ReplyWithError(ctx, "Arg cannot be parsed as a double"); + dbl /= dbl2; + } return RedisModule_ReplyWithDouble(ctx, dbl); } |