Redis Hash: HINCRBYFLOAT
Redis HINCRBYFLOAT command
Redis HINCRBYFLOAT command is used to increment the specified field of a hash stored at key, and representing a floating point number, by the specified increment. If the field does not exist, it is set to 0 before performing the operation. If the field contains a value of wrong type or specified increment is not parsable as floating point number, then an error has occurred.
Here are some common uses and scenarios for the "HINCRBYFLOAT" command:
- Increment Counters: Update floating-point counters stored in a hash for precise tracking.
- Financial Calculations: Adjust monetary values or prices within a hash.
- Score Keeping: Increment floating-point scores or points for users or items.
- Atomic Operations: Ensure atomicity when incrementing floating-point values in hash fields in a multi-client environment.
- Dynamic Data Updates: Efficiently update numeric values within a hash without retrieving and modifying the entire hash.
Syntax:
HINCRBYFLOAT KEY_NAME FIELD_NAME INCR_BY_NUMBER
Available since
2.6.0.
Return Value
String reply, the value of field after the increment.
Return Value Type
Integer
Example: Redis HINCRBYFLOAT
127.0.0.1:6379> HSET langhash lang1 10.25 (integer) 1 127.0.0.1:6379> HINCRBYFLOAT langhash lang1 0.2 "10.45" 127.0.0.1:6379> HSET langhash lang1 6.0e4 (integer) 1 127.0.0.1:6379> HINCRBYFLOAT langhash lang1 3.0e3 "63000"
Example: Redis HINCRBYFLOAT another example
127.0.0.1:6379> HINCRBYFLOAT user height 85.5 "85.5" 127.0.0.1:6379> HINCRBYFLOAT user height 14.2 "99.7" 127.0.0.1:6379> HINCRBYFLOAT user height -12.5 "87.2" 127.0.0.1:6379> HINCRBYFLOAT user height 85.5 "172.7" 127.0.0.1:6379> HINCRBYFLOAT user height -85.7 "87"
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/redis/redis-hincrbyfloat-key-field-increment.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics