Redis HSTRLEN – How to get a length of the field value contained in hash

3 weeks ago Lalit Bhagtani 0

In this tutorial, we will learn about how to get the length ( number of characters ) of a value associated with the field in the hash value stored at a key, by using a COMMAND – HSTRLEN in redis-cli.

This command, returns 0 if key does not exist or if key exist but hash value does not contains the specified field and returns error if key exist but value stored at the key is not of hash datatype. The syntax of redis HSTRLEN command is as follows :-

Syntax :-

redis host:post> HSTRLEN <keyname> <field>

Output :- 

- (integer) reply, representing the length of a field value in the hash.
- (integer) 0, if a hash value does not contain the field or if key does not exist.
- Error, if key exist and value stored at the key is not a hash.

Example :-


References :-

  1. HSTRLEN Command Docs

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