w3resource

Redis String: STRLEN key

Redis STRLEN command

Redis STRLEN command is used to get the length of the string value stored at key. An error is returned when key holds a non-string value.

Here are some common uses and scenarios for the "STRLEN" command:

  • String Length Retrieval: Retrieve the number of characters in a string value.
  • Data Validation: Check the length of input strings or data stored in Redis.
  • String Operations: Determine the size of strings for efficient memory management.
  • Protocol Handling: Manage and validate data lengths in custom protocols.

Syntax:

redis 127.0.0.1:6379> STRLEN KEY_NAME

Available since

2.2.0.

Return Value

Integer reply, the length of the string at the key, or 0 when the key does not exist.

Return Value Type

Integer

Example: Redis STRLEN

redis 127.0.0.1:6379> SET key1 "Redis"
OK
redis 127.0.0.1:6379>  STRLEN key1
(integer) 5

Previous: SETRANGE
Next: MSET



Follow us on Facebook and Twitter for latest update.