# CMS.INITBYDIM

> Create a Count-min sketch with an explicit width and depth.

URL: https://docs.hotkv.com/commands/cms-initbydim/

```
CMS.INITBYDIM key width depth
```

- Group: Count-min sketch
- Complexity: O(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](https://docs.hotkv.com/commands/cms-initbyprob/index.md).

## Return value

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

## Examples

```
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
```

## Compatibility

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

## See also

[CMS.INITBYPROB](https://docs.hotkv.com/commands/cms-initbyprob/index.md), [CMS.INCRBY](https://docs.hotkv.com/commands/cms-incrby/index.md), [CMS.QUERY](https://docs.hotkv.com/commands/cms-query/index.md),
[CMS.INFO](https://docs.hotkv.com/commands/cms-info/index.md)