Redis入门之List

Redis入门之List

  1. 可描述栈的形式

同向命令 push 、pop可用作栈使用

  1. 队列,方向队列

反向向命令 push 、pop可作为队列使用

  1. lindex,lset情况下

作为数组使用

  1. 阻塞操作

单播队列,FIFO

  1. lpush /RPUSH

从头添加

  LPUSH key value [value ...]
  summary: Prepend one or multiple values to a list
  since: 1.0.0

从尾添加

RPUSH key value [value ...]
  summary: Append one or multiple values to a list
  since: 1.0.0
  1. lpop/rpop

头、尾弹出

LPOP key
  summary: Remove and get the first element in a list
  since: 1.0.0
RPOP key
  summary: Remove and get the last element in a list
  since: 1.0.0
  1. lrange

获取范围的元素

LRANGE key start stop
  summary: Get a range of elements from a list
  since: 1.0.0
  1. lindex
    得到index的元素
  LINDEX key index
  summary: Get an element from a list by its index
  since: 1.0.0
  1. lset
    设置index位置的值
LSET key index value
  summary: Set the value of an element in a list by its index
  since: 1.0.0
  1. lrem 移除
LREM key count value
  summary: Remove elements from a list
  since: 1.0.0

count :移除个数

value : 要移除的值

  1. linsert
    插入

  LINSERT key BEFORE|AFTER pivot value
  summary: Insert an element before or after another element in a list
  since: 2.2.0

pivot :位置 index

  1. 阻塞操作
// 阻塞左弹出
  BLPOP key [key ...] timeout
  summary: Remove and get the first element in a list, or block until one is available
  since: 2.0.0
// 阻塞右弹出
  BRPOP key [key ...] timeout
  summary: Remove and get the last element in a list, or block until one is available
  since: 2.0.0
// 阻塞右 弹出左插入
  BRPOPLPUSH source destination timeout
  summary: Pop a value from a list, push it to another list and return it; or block until one is available
  since: 2.2.0



  1. ltrim
LTRIM key start stop
  summary: Trim a list to the specified range
  since: 1.0.0

删除2端的元素,保留start - end的元素



  LLEN key
  summary: Get the length of a list
  since: 1.0.0


  LPUSHX key value
  summary: Prepend a value to a list, only if the list exists
  since: 2.2.0


  RPOPLPUSH source destination
  summary: Remove the last element in a list, prepend it to another list and return it
  since: 1.2.0



  RPUSHX key value
  summary: Append a value to a list, only if the list exists
  since: 2.2.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多多洛码代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值