本文内容为 http://redis.io/commands/incrbyfloat 的翻译、注解、例子扩充及其它修改。感谢 Redis 作者 Antirez 为开源社区作出的贡献,本文保证最新、最准、最全以表示对其的敬意。欢迎留言纠错、提示更新或支持。
INCRBYFLOAT key increment

为存储在键 key 中的代表浮点数(Floating point number)的字符串值增加指定的增量 increment

如果键 key 不存在,在进行该操作前,将会被创建并置 0

Increment the string representing a floating point number stored at key by the specified increment. If the key does not exist, it is set to 0 before performing the operation

当出现如下任意一种情况将反回一个错误:

  • key 所对应的值的类型错误(非字符串)。
  • key 所对应的值或指定的增量 increment 不能被解析(Not parsable)为双精度浮点数(Double precision floating point number)
The key contains a value of the wrong type (not a string).
The current key content or the specified increment are not parsable as a double precision floating point number.

发果执行成功,增加后的值将被保存为键 key 的新值(替代旧值),且以字符串形式返回给调用者(Caller)

无论是已经保存在字符串键(string key)中的值,还是增量参数,都可以随意地用指数计数法(Exponential notation)表示。然而,在进行增量操作后,值总是以相同的格式存储。

Both the value already contained in the string key and the increment argument can be optionally provided in exponential notation, however the value computed after the increment is stored consistently in the same format, that is, an integer number followed (if needed) by a dot, and a variable number of digits representing the decimal part of the number. Trailing zeroes are always removed

不管计算获得的浮点数的实际内部精度(Actual internal precision)是多少, 输出精度(Precision of the output)总是固定为小数点的后 17 位。

The precision of the output is fixed at 17 digits after the decimal point regardless of the actual internal precision of the computation.