redis INCRBYFLOAT command


  Translation results:

incr

abbr.increase (value, price, inventory, amount, production, etc.) increase;increasing increase;increased increase;incremental increase

by

英[baɪ] 美[baɪ]

prep.beside...;expression method;due to;passing through

adv.passing;expressing reservation Or use when saving; short visit

float

英[fləʊt] 美[floʊt]

vt.& vi. (make) float; (make) float; float freely

vi. wander

vt. put forward, draw for consideration; (stock) go public

n. float; floating object; floating board; A drink with ice cream floating on it

Third person singular: floats Plural: floats Present participle: floating Past tense: floated Past participle: floated

redis INCRBYFLOAT commandsyntax

Function: Adds floating point increment to the value stored in key.

Syntax: INCRBYFLOAT key increment

Description: If key does not exist, then INCRBYFLOAT will first set the value of key to 0 before executing Addition operation. If the command is executed successfully, the value of key will be updated to the new value (after the addition), and the new value will be returned to the caller in the form of a string. Whether it is the value of key or the increment, it can be represented by exponential notation like 2.0e7, 3e5, 90e-2. However, the value after executing the INCRBYFLOAT command is always stored in the same form. That is, they always consist of a number, an (optional) decimal point, and a decimal part of any digit (such as 3.14, 69.768, etc.), with trailing 0's removed if necessary. Floating point numbers will also be changed to integers (for example, 3.0 will be saved as 3 ). In addition, no matter how long the actual precision of the floating point number obtained by the addition is, the calculation result of INCRBYFLOAT can only represent up to seventeen decimal places.

Available versions: >= 2.6.0

Time complexity: O(1)

Return: The value of key after executing the command.

redis INCRBYFLOAT commandexample

# 值和增量都不是指数符号
redis> SET mykey 10.50
OK
redis> INCRBYFLOAT mykey 0.1
"10.6"
# 值和增量都是指数符号
redis> SET mykey 314e-2
OK
redis> GET mykey                # 用 SET 设置的值可以是指数符号
"314e-2"
redis> INCRBYFLOAT mykey 0      # 但执行 INCRBYFLOAT 之后格式会被改成非指数符号
"3.14"
# 可以对整数类型执行
redis> SET mykey 3
OK
redis> INCRBYFLOAT mykey 1.1
"4.1"
# 后跟的 0 会被移除
redis> SET mykey 3.0
OK
redis> GET mykey                                    # SET 设置的值小数部分可以是 0
"3.0"
redis> INCRBYFLOAT mykey 1.000000000000000000000    # 但 INCRBYFLOAT 会将无用的 0 忽略掉,有需要的话,将浮点变为整数
"4"
redis> GET mykey
"4"

Home

Videos

Q&A