Redis Hincrby Command | SimplestTutorials.com
Learn not just technology, but also dreams!
Redis Tutorial
Redis Commands
- Redis Commands
- Redis Keys (Key)
- Redis Strings (String)
- Redis Hashes (Hash)
- Redis Lists (List)
- Redis Sets (Set)
- Redis Sorted Sets (Sorted Set)
- Redis HyperLogLog
- Redis Pub/Sub
- Redis Transactions
- Redis Scripting
- Redis Connection
- Redis Server
- Redis GEO
- Redis Stream
Advanced Redis Tutorials
- Redis Backup and Restore
- Redis Security
- Redis Performance Testing
- Redis Client Connection
- Redis Pipelining
- Redis Partitioning
- Java Using Redis
- PHP Using Redis
Note: This tutorial is part of the comprehensive learning journey offered by SimplestTutorials.com β where we donβt just teach technology, we inspire dreams.
Redis Hincrby Command
The HINCRBY command in Redis is used to increment the value of a field in a hash table by a specified amount.
The increment can also be negative, which effectively performs a subtraction operation on the specified field.
If the hash table key does not exist, a new hash table will be created and the HINCRBY command will be executed.
If the specified field does not exist, its value is initialized to 0 before executing the command.
Executing HINCRBY on a field that stores a string value will result in an error.
The value of this operation is restricted to a 64-bit signed integer.
Syntax
The basic syntax for the Redis HINCRBY command is as follows:
redis 127.0.0.1:6379> HINCRBY KEY_NAME FIELD_NAME INCR_BY_NUMBER
Available Version
>= 2.0.0
Returns
The updated value of the field in the hash table after executing the HINCRBY command.
Examples
redis> HSET myhash field 5 (integer) 1 redis> HINCRBY myhash field 1 (integer) 6 redis> HINCRBY myhash field -1 (integer) 5 redis> HINCRBY myhash field -10 (integer) -5 redis>
YouTip