redis linux list,Redis关于list类型操作

Redis关于list类型操作

1>栈的特性:先进后出,后进先出

2>队列的特性:先进先出,后进后出

List是一个链表结构,既可可以做为栈也可以作为队列处理数据.

lpush mylist "world" //向mylist尾部中放入world

lpush mylist "hello" //向mylist尾部中存入hello

lrange 0 -1 //获取mylist中的所有元素

rpush mylist2 "hello" //向mylist头部中存入hello

rpush mylist2 "world" //向mylist头部中存入world

lrange 0 -1

linsert mylist2 before world "xhy" //向mylist中world元素前插入"xhy"

lset mylist2 0 "example" //设置mylist中的第0个元素的值为"example"

lpush mylist_rem "one"

lpush mylist_rem "one"

lpush mylist_rem "one"

lrem mylist_rem 1 "one //删除1个值为"one"的元素

lpush mylist_ltrim "one"

lpush mylist_ltrim "two"

lpush mylist_ltrim "three"

lpush mylist_ltrim "four"

lpush mylist_ltrim "five"

ltrim mylist_ltrim 2 3 //除了第2和第3个元素,删除其它元素

lpush list_pop 1

lpush list_pop 1

lpush list_pop 1

lrange list_pop 0 -1

lpop list_pop //从头部删除list_pop的第一个元素

rpop list_pop //从尾部删除list_pop的第一个元素

lpush list_1 0

lpush list_1 1

lpush list_1 2

lpush list_1 3

lrange list_1 0 -1

lpush list_2 4

lpush list_2 5

lpush list_2 6

lpush list_2 7

lrange list_2 0 -1

rpoplpush list_1 list_2 //从list_1中的尾部弹出第1个元素并添加到list_2的头部中

lindex list_2 0 //取出list_2第0个元素

lindex list_2 1

llen //返回链表的长度

推荐阅读:

Redis 的详细介绍:请点这里

Redis 的下载地址:请点这里0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值