# XGROUP CREATE

> Create a consumer group on a stream, starting after a given ID.

URL: https://docs.hotkv.com/commands/xgroup-create/

```
XGROUP CREATE key group <id | $> [MKSTREAM] [ENTRIESREAD entries-read]
```

- Group: Stream
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`XGROUP CREATE` creates the consumer group `group` on the stream at `key`. The
group delivers, through [XREADGROUP](https://docs.hotkv.com/commands/xreadgroup/index.md) with `>`, the
entries with an ID greater than the one you give:

- `$`: only entries added from now on.
- `0`: every entry already in the stream, then new ones.
- Any other ID: entries after it.

## Options

| Option | Effect |
| --- | --- |
| `MKSTREAM` | Create an empty stream if the key does not exist. |
| `ENTRIESREAD entries-read` | Tell the group how many entries it has already read, so XINFO GROUPS can show its lag. `-1` (the default) means unknown. |

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Group created | Simple string `OK` | Simple string `OK` |

Error replies:

- `BUSYGROUP Consumer Group name already exists`
- `ERR The XGROUP subcommand requires the key to exist. Note that for CREATE you may want to use the MKSTREAM option to create an empty stream automatically.`
- `ERR Invalid stream ID specified as stream command argument`
- `ERR value for ENTRIESREAD must be positive or -1`
- `ERR unknown subcommand or wrong number of arguments for 'CREATE'. Try XGROUP HELP.` for an unknown option.
- `WRONGTYPE` if the key holds another type.

## Examples

```
127.0.0.1:6379> XGROUP CREATE orders billing $
(error) ERR The XGROUP subcommand requires the key to exist. Note that for CREATE you may want to use the MKSTREAM option to create an empty stream automatically.
127.0.0.1:6379> XGROUP CREATE orders billing $ MKSTREAM
OK
127.0.0.1:6379> XGROUP CREATE orders billing 0
(error) BUSYGROUP Consumer Group name already exists
127.0.0.1:6379> XGROUP CREATE orders audit 0
OK
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[XGROUP](https://docs.hotkv.com/commands/xgroup/index.md), [XGROUP SETID](https://docs.hotkv.com/commands/xgroup-setid/index.md), [XGROUP DESTROY](https://docs.hotkv.com/commands/xgroup-destroy/index.md),
[XREADGROUP](https://docs.hotkv.com/commands/xreadgroup/index.md), [XINFO GROUPS](https://docs.hotkv.com/commands/xinfo-groups/index.md)