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.INITBYDIM

Last updated
CMS.INITBYDIM key width depth
Group
Count-min sketch
Complexity
O(1)
Arity
-1 (at least 1 words, counting the command name)
Flags
fast
Keys
first 1, last 1, step 1
HotKV Cloud
All plans
On-Premise
no license needed

CMS.INITBYDIM creates an empty Count-min sketch at key. A Count-min sketch counts how often items occur in a stream of events using a fixed amount of memory. Its estimates are never lower than the true count, and can be higher.

The sketch has depth rows of width counters. A larger width lowers the overcount; a larger depth makes a large overcount less likely. Memory grows with width times depth. If you would rather state the accuracy you need, use CMS.INITBYPROB.

Case RESP2 RESP3
Created Simple string OK Simple string OK

Error replies:

  • CMS: key already exists if the key exists (with any type).
  • CMS: invalid width and CMS: invalid depth for values that are not positive integers.
  • CMS: invalid init arguments when width times depth is too large to count.
  • CMS: Insufficient memory to create the key when the sketch would not fit in memory (a single sketch is limited to 4 GiB).
127.0.0.1:6379> CMS.INITBYDIM pageviews 2000 5
OK
127.0.0.1:6379> CMS.INITBYDIM pageviews 2000 5
(error) CMS: key already exists
127.0.0.1:6379> CMS.INFO pageviews
1) width
2) (integer) 2000
3) depth
4) (integer) 5
5) count
6) (integer) 0

Same as CMS.INITBYDIM in RedisBloom. HotKV also refuses sketches larger than 4 GiB.

CMS.INITBYPROB, CMS.INCRBY, CMS.QUERY, CMS.INFO