Redis HINCRBYFLOAT – How to increment a floating point number stored at field in hash value
2 months ago Lalit Bhagtani 0
In this tutorial, we will learn about how to increment the floating point number stored at a field inside the hash value stored at key in redis datastore. For this we will use a COMMAND – HINCRBYFLOAT in redis-cli.
This command is used to increment the floating point number stored at a specified field in the hash value stored at key by a specified value (increment). If given field does not exist in the hash value, then it is added with the specified increment as its value. If key does not exist, a new hash value is created with the given field as its only member. If negative floating point number is passed as an argument then field value will be decremented instead of incremented.
An error is returned, if key exist but value stored at a key is not of hash datatype or if field value or the specified increment value are not a double precision floating point number.
The syntax of redis HINCRBYFLOAT command is as follows :-
redis host:post> HINCRBYFLOAT <keyname> <field> <increment>
- (string) reply, representing the new value stored at the field. - Error, if key exist and value stored at the key is not a hash.
That’s all for how to increment the floating point number stored at a field 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.