STRLEN
STRLEN key
- Group
- String
- Complexity
- O(1)
- Arity
- 2 (exactly, counting the command name)
- Flags
- read-only, fast
- Keys
- first 1, last 1, step 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
Section titled “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
Section titled “Examples”127.0.0.1:6379> SET name "Ada Lovelace"OK127.0.0.1:6379> STRLEN name(integer) 12127.0.0.1:6379> SET big 1000000OK127.0.0.1:6379> STRLEN big(integer) 7127.0.0.1:6379> STRLEN missing(integer) 0Compatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.