Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

CMS.MERGE

Last updated
CMS.MERGE destination numkeys source [source ...] [WEIGHTS weight [weight ...]]
Group
Count-min sketch
Complexity
O(n * width * depth), n being the sources
Arity
-1 (at least 1 words, counting the command name)
Flags
none
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

CMS.MERGE sets the Count-min sketch at destination to the sum of the numkeys source sketches, counter by counter. With WEIGHTS, each source is multiplied by its weight first. Use it to combine sketches kept per server, per shard or per time window.

The destination must already exist, and every sketch must have the same width and depth (create them with the same arguments). The destination’s previous counts are replaced, not added to; list it among the sources to add to it.

Option Effect
WEIGHTS weight ... One integer weight per source, in order (default 1 each). Weights may be negative, as long as no counter ends below 0.
Case RESP2 RESP3
Merged Simple string OK Simple string OK

Error replies:

  • CMS: key does not exist if the destination or a source is missing.
  • CMS: width/depth is not equal
  • CMS: invalid numkeys and CMS: Number of keys must be positive
  • CMS: wrong number of keys and CMS: wrong number of keys/weights
  • CMS: invalid weight value
  • CMS: MERGE overflow when a counter would go below 0 or past 4294967295 (the destination is left unchanged).
  • WRONGTYPE if a key holds another type.
127.0.0.1:6379> CMS.INITBYDIM day1 2000 5
OK
127.0.0.1:6379> CMS.INITBYDIM day2 2000 5
OK
127.0.0.1:6379> CMS.INITBYDIM week 2000 5
OK
127.0.0.1:6379> CMS.INCRBY day1 /home 10
1) (integer) 10
127.0.0.1:6379> CMS.INCRBY day2 /home 4
1) (integer) 4
127.0.0.1:6379> CMS.MERGE week 2 day1 day2
OK
127.0.0.1:6379> CMS.QUERY week /home
1) (integer) 14
127.0.0.1:6379> CMS.MERGE week 2 day1 day2 WEIGHTS 1 2
OK
127.0.0.1:6379> CMS.QUERY week /home
1) (integer) 18

Same as CMS.MERGE in RedisBloom, including the requirement that the destination exists.

CMS.INITBYDIM, CMS.QUERY, CMS.INFO