redis HINCRBY command
Translation results:
incr
increase increase; increase increase; increase increase; increase increase
by
英[ baɪ] 美[baɪ]
prep.beside...;expression method;due to;passing through
adv.passing;expressing retention or preservation; short visit
redis HINCRBY commandsyntax
Function: Add increment to the value of field field in hash table key.
Syntax: HINCRBY key field increment
Explanation: The increment can also be a negative number, which is equivalent to subtracting a given field. If key does not exist, a new hash table is created and the HINCRBY command is executed. If the field field does not exist, the value of the field is initialized to 0 before executing the command. Executing the HINCRBY command on a field that stores string values will cause an error. The value of this operation is limited to a 64-bit signed number representation.
Available versions: >= 2.0.0
Time complexity: O(1)
Return: After executing the HINCRBY command, the value of the field field in the hash table key.
redis HINCRBY commandexample
# increment 为正数 redis> HEXISTS counter page_view # 对空域进行设置 (integer) 0 redis> HINCRBY counter page_view 200 (integer) 200 redis> HGET counter page_view "200" # increment 为负数 redis> HGET counter page_view "200" redis> HINCRBY counter page_view -50 (integer) 150 redis> HGET counter page_view "150" # 尝试对字符串值的域执行HINCRBY命令 redis> HSET myhash string hello,world # 设定一个字符串值 (integer) 1 redis> HGET myhash string "hello,world" redis> HINCRBY myhash string 1 # 命令执行失败,错误。 (error) ERR hash value is not an integer redis> HGET myhash string # 原值不变 "hello,world"