Commande Redis Incrbyfloat

Chaîne Redis

La commande Redis Incrbyfloat ajoute la valeur d'incrément à virgule flottante spécifiée à la valeur stockée dans key.

Si key n'existe pas, INCRBYFLOAT définit d'abord la valeur de key à 0, puis effectue l'opération d'addition.

Syntaxe

La syntaxe de base de la commande redis Incrbyfloat est la suivante :

redis 127.0.0.1:6379> INCRBYFLOAT KEY_NAME INCR_AMOUNT

Versions disponibles

>= 2.6.0

Valeur de retour

La valeur de la clé après l'exécution de la commande.

Exemples

# 值和增量都不是指数符号

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"

Chaîne Redis

Autres extensions