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

如果键 key 已经存在,且对应的值是一个字符串, 该命令会将 value 追加到 key 原来的值的末尾。

如果键 key 不存在, 该命令将会创建键 key ,并设值为 value ,此时等同于 SET 命令。

If key already exists and is a string, this command appends the value at the end of the string. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.

  • 执行追加操作后的值(字符串)长度

  • redis> EXISTS mykey
    (integer) 0
    redis> APPEND mykey "Hello"
    (integer) 5
    redis> APPEND mykey " World"
    (integer) 11
    redis> GET mykey
    "Hello World"
    redis> SET foo bar
    OK
    redis> EXPIRE foo 100000
    (integer) 1
    redis> GET foo
    "bar"
    redis> APPEND foo 123
    (integer) 3
    redis> GET foo
    "123"
  • 版本支持

    2.0.0+

    时间复杂度(Time complexity)

    O(1)

    Time complexity: O(1). The amortized time complexity is O(1) assuming the appended value is small and the already present value is of any size, since the dynamic string library used by Redis will double the free space available on every reallocation.