From 9e1b879f5bcbf105d5581c77f8c368b0ef1708f6 Mon Sep 17 00:00:00 2001 From: Binbin Date: Sun, 23 Oct 2022 01:41:17 +0800 Subject: Make PFMERGE source key optional in docs, add tests with one input key, add tests on missing source keys (#11205) The following two cases will create an empty destkey HLL: 1. called with no source keys, like `pfmerge destkey` 2. called with non-existing source keys, like `pfmerge destkey non-existing-source-key` In the first case, in `PFMERGE`, the dest key is actually one of the source keys too. So `PFMERGE k1 k2` is equivalent to `SUNIONSTORE k1 k1 k2`, and `PFMERGE k1` is equivalent to `SUNIONSTORE k1 k1`. So the first case is reasonable, the source key is actually optional. And the second case, `PFMERGE` on missing keys should succeed and create an empty dest. This is consistent with `PFCOUNT`, and also with `SUNIONSTORE`, no need to change. --- src/commands.c | 2 +- src/commands/pfmerge.json | 1 + src/help.h | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/commands.c b/src/commands.c index 5ee012c79..b9b4b915d 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2608,7 +2608,7 @@ struct redisCommandArg PFDEBUG_Args[] = { /* PFMERGE argument table */ struct redisCommandArg PFMERGE_Args[] = { {"destkey",ARG_TYPE_KEY,0,NULL,NULL,NULL,CMD_ARG_NONE}, -{"sourcekey",ARG_TYPE_KEY,1,NULL,NULL,NULL,CMD_ARG_MULTIPLE}, +{"sourcekey",ARG_TYPE_KEY,1,NULL,NULL,NULL,CMD_ARG_OPTIONAL|CMD_ARG_MULTIPLE}, {0} }; diff --git a/src/commands/pfmerge.json b/src/commands/pfmerge.json index ae18dad1e..648a8b43a 100644 --- a/src/commands/pfmerge.json +++ b/src/commands/pfmerge.json @@ -62,6 +62,7 @@ "name": "sourcekey", "type": "key", "key_spec_index": 1, + "optional": true, "multiple": true } ] diff --git a/src/help.h b/src/help.h index a95da3695..e8a94210e 100644 --- a/src/help.h +++ b/src/help.h @@ -1125,7 +1125,7 @@ struct commandHelp { 11, "2.8.9" }, { "PFMERGE", - "destkey sourcekey [sourcekey ...]", + "destkey [sourcekey [sourcekey ...]]", "Merge N different HyperLogLogs into a single one.", 11, "2.8.9" }, -- cgit v1.2.1