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

5 years ago Lalit Bhagtani 0

In this tutorial, we will learn about how to get a length of the field’s value contained in the hash value stored at a key. For this, we will use Redis HSTRLEN command.

HSTRLEN Command

This command returns the length ( number of characters ) of a value associated with the field in the hash value stored at a specified key. O is returned, if the key does not exist or if the key exists but hash value does not contain the specified field and an error is returned, if the key exists but value stored at the key is not of a hash datatype. The syntax of the 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 :-

Redis HSTRLEN

References :-

  1. HSTRLEN Command Docs

That’s all for how to get a length of the field’s 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.

<- Hash Commands