Use STRLEN to get the length in bytes of the string stored at a key.
The reply is 0 when the key does not exist, and an error when the value is not a string. Since the value itself is never transferred, it is the cheap way to check how large a value is, for instance before deciding whether to fetch it or to read only part of it with GETRANGE. The count is in bytes, so multi-byte characters count more than once.
Syntax#
Arguments#
| Argument | Required | Repeatable | Description |
|---|---|---|---|
<key> | Yes | No | Redis key targeted by the command. |
Response#
The reply reports the result of the operation. Error replies have the same shape in RESP2 and RESP3 and are surfaced as exceptions by the SDKs below.
| Protocol | Reply |
|---|---|
| RESP2 | Integer |
| RESP3 | Integer |
Client libraries often decode bulk strings, maps, sets, and numeric strings into language-native values. The table describes the Redis wire reply.
Examples#
TCP examples use the TLS REDIS_URL from the Upstash console. REST examples use UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN.