# COMMAND GETKEYS

> Return the key arguments of a full command line without running it.

URL: https://docs.hotkv.com/commands/command-getkeys/

```
COMMAND GETKEYS command [argument ...]
```

- Group: Server
- Complexity: O(N) where N is the number of arguments
- HotKV Cloud: all plans
- On-Premise: no license needed

`COMMAND GETKEYS` takes a complete command, with its arguments, and returns
which of the arguments are keys. Nothing is run. Cluster clients use it for
commands whose keys cannot be found from fixed positions, such as
[EVAL](https://docs.hotkv.com/commands/eval/index.md), [SORT](https://docs.hotkv.com/commands/sort/index.md) with `STORE`, or
[ZUNIONSTORE](https://docs.hotkv.com/commands/zunionstore/index.md).

## Return value

An array of the key arguments as bulk strings, in RESP2 and RESP3.

Errors:

| Case | Error |
| --- | --- |
| Unknown command | `ERR Invalid command specified` |
| Wrong number of arguments for that command | `ERR Invalid number of arguments specified for command` |
| The command takes no keys | `ERR The command has no key arguments` |
| The arguments that locate the keys are not valid (for example a bad `numkeys`) | `ERR Invalid arguments specified for command` |

A script command ([EVAL](https://docs.hotkv.com/commands/eval/index.md), [FCALL](https://docs.hotkv.com/commands/fcall/index.md) and
their variants) with `numkeys` 0 returns an empty array rather than an
error.

## Examples

```
127.0.0.1:6379> COMMAND GETKEYS MSET a 1 b 2
1) "a"
2) "b"
127.0.0.1:6379> COMMAND GETKEYS SORT mylist BY weight_* STORE sorted
1) "mylist"
2) "sorted"
127.0.0.1:6379> COMMAND GETKEYS EVAL "return 1" 2 k1 k2 arg
1) "k1"
2) "k2"
127.0.0.1:6379> COMMAND GETKEYS PING
(error) ERR The command has no key arguments
```

## Compatibility

Same replies and error strings as Redis 7 and Valkey 8.

## See also

[COMMAND GETKEYSANDFLAGS](https://docs.hotkv.com/commands/command-getkeysandflags/index.md),
[COMMAND INFO](https://docs.hotkv.com/commands/command-info/index.md), [CLUSTER KEYSLOT](https://docs.hotkv.com/commands/cluster-keyslot/index.md)