Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

STRLEN

Last updated
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.

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.

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

Same as Redis 7 and Valkey 8.

GETRANGE, APPEND, GET