Redis HEXISTS – How to check existence of field in hash value in redis

3 weeks ago Lalit Bhagtani 0

In this tutorial, we will learn about how to check, if a field exists in the hash value stored at a key or not. For this we will use a COMMAND – HEXISTS in redis-cli.

1 is returned, if the hash value stored at a key contains the specified field and 0 is returned, if key does not exist or if key exist but hash value does not contains the specified field.

Error is returned, if key exist but value stored at the key is not of hash datatype. The syntax of redis HEXISTS command is as follows :-

Syntax :-

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

Output :- 

- (integer) 1, if a hash value contain the field.
- (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 HEXISTS

References :-

  1. HEXISTS Command Docs

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