CMS.MERGE
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.
Options
Section titled “Options”| 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. |
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Merged | Simple string OK |
Simple string OK |
Error replies:
CMS: key does not existif the destination or a source is missing.CMS: width/depth is not equalCMS: invalid numkeysandCMS: Number of keys must be positiveCMS: wrong number of keysandCMS: wrong number of keys/weightsCMS: invalid weight valueCMS: MERGE overflowwhen a counter would go below 0 or past 4294967295 (the destination is left unchanged).WRONGTYPEif a key holds another type.
Examples
Section titled “Examples”127.0.0.1:6379> CMS.INITBYDIM day1 2000 5OK127.0.0.1:6379> CMS.INITBYDIM day2 2000 5OK127.0.0.1:6379> CMS.INITBYDIM week 2000 5OK127.0.0.1:6379> CMS.INCRBY day1 /home 101) (integer) 10127.0.0.1:6379> CMS.INCRBY day2 /home 41) (integer) 4127.0.0.1:6379> CMS.MERGE week 2 day1 day2OK127.0.0.1:6379> CMS.QUERY week /home1) (integer) 14127.0.0.1:6379> CMS.MERGE week 2 day1 day2 WEIGHTS 1 2OK127.0.0.1:6379> CMS.QUERY week /home1) (integer) 18Compatibility
Section titled “Compatibility”Same as CMS.MERGE in RedisBloom, including the requirement that the
destination exists.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.