# STRLEN

> Return the length in bytes of the string stored at a key.

URL: https://docs.hotkv.com/commands/strlen/

```
STRLEN key
```

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

`STRLEN` returns the length of the string at `key`, in bytes. A missing key
has length `0`. For a number stored as an integer, it is the length of its
decimal text.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Always | Integer: the length (0 for a missing key) | Integer |

`STRLEN` replies with a `WRONGTYPE` error when the key holds a value that is
not a string.

## Examples

```
127.0.0.1:6379> SET name "Ada Lovelace"
OK
127.0.0.1:6379> STRLEN name
(integer) 12
127.0.0.1:6379> SET big 1000000
OK
127.0.0.1:6379> STRLEN big
(integer) 7
127.0.0.1:6379> STRLEN missing
(integer) 0
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[GETRANGE](https://docs.hotkv.com/commands/getrange/index.md), [APPEND](https://docs.hotkv.com/commands/append/index.md),
[GET](https://docs.hotkv.com/commands/get/index.md)