修改本页

Redis 命令 客户端 文档 社区 下载 问题 支持 许可

LINSERT key BEFORE|AFTER pivot value

相关命令

Available since 2.2.0.

时间复杂度: O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N).

Inserts value in the list stored at key either before or after the reference value pivot.

When key does not exist, it is considered an empty list and no operation is performed.

An error is returned when key exists but does not hold a list value.

返回值

Integer reply: the length of the list after the insert operation, or -1 when the value pivot was not found.

例子

redis> RPUSH mylist "Hello"

  1. (integer) 1

redis> RPUSH mylist "World"

  1. (integer) 2

redis> LINSERT mylist BEFORE "World" "There"

  1. (integer) 3

redis> LRANGE mylist 0 -1

  1. 1) "Hello"
  2. 2) "There"
  3. 3) "World"
redis>

Comments powered by Disqus

This website is open source software developed by Citrusbyte.

The Redis logo was designed by Carlos Prioglio. See more credits.

Sponsored by Redis Support