summaryrefslogtreecommitdiff
path: root/tests/modules
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2022-11-13 13:12:22 +0200
committerGitHub <noreply@github.com>2022-11-13 13:12:22 +0200
commit78dc29217846d7706397c5518de95e0f49795b43 (patch)
treea5f47d81b59f31bc2df501831d8582c8b8237010 /tests/modules
parent4c54528f0fb56dec1373ead376a017b59743b04e (diff)
downloadredis-78dc29217846d7706397c5518de95e0f49795b43.tar.gz
Add test to cover NAN reply using a module (#11482)
Adding a test to cover the already existing behavior of NAN replies, to accompany the PR that adds them to the RESP3 spec: https://github.com/redis/redis-specifications/pull/10 This PR also covers Inf replies that are already in the spec, as well as RESP2 coverage.
Diffstat (limited to 'tests/modules')
-rw-r--r--tests/modules/reply.c15
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);
}