Redis STRLEN – How to get a length of the string value in redis datastore

1 month ago Lalit Bhagtani 0

In this tutorial, we will learn about how to get the length ( number of characters ) of a string value stored at the key, by using a COMMAND – STRLEN in redis-cli. If key doesn’t exist in redis datastore, it is interpreted as an empty string and 0 is returned. The syntax of redis STRLEN command is as follows :-

Syntax :-

redis host:post> STRLEN <key name>

Output :- 

(integer) value, representing the number of characters in the string.
(integer) 0, if key does not exist.
Error, if key exist and value stored at the key is not a string.

Example :-

Redis STRLEN

References :-

  1. STRLEN Command Docs

That’s all for how to get the length of a string value stored in redis datastore. If you liked it, please share your thoughts in comments section and share it with others too.