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

2 months ago Lalit Bhagtani 0

In this tutorial, we will learn about how to get the length of a string value stored at the key. For this, we will use a Redis STRLEN command.

STRLEN Command

This command returns the length ( number of characters ) of a string value stored at a key. If the 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.

<- String Commands