关于redis之lpush、rpush、lset、lrem


本文摘自PHP中文网,作者藏色散人,侵删。

下面由Redis教程栏目给大家介绍redis之lpush、rpush、lset、lrem,希望对需要的朋友有所帮助!

1.lpush

在key对应 list的头部添加字符串元素

2.rpush

在key对应 list 的尾部添加字符串元素

3.linsert

在key对应 list 的特定位置之前或之后添加字符串元素

1

2

3

4

5

6

7

8

9

10

11

redis 127.0.0.1:6379> rpush mylist3 "hello"

(integer) 1

redis 127.0.0.1:6379> rpush mylist3 "world"

(integer) 2

redis 127.0.0.1:6379> linsert mylist3 before "world" "there"

(integer) 3

redis 127.0.0.1:6379> lrange mylist3 0 -1

1) "hello"

2) "there"

3) "world"

redis 127.0.0.1:6379>

在此处我们先插入了一个 hello,然后在 hello 的尾部插入了一个 world,然后又在 world 的

前面插入了 there。

4.lset

设置list中指定下标的元素值(下标从0开始)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

redis 127.0.0.1:6379> rpush mylist4 "one"

(integer) 1

redis 127.0.0.1:6379> rpush mylist4 "two"

(integer) 2

redis 127.0.0.1:6379> rpush mylist4 "three"

(integer) 3

redis 127.0.0.1:6379> lset mylist4 0 "four"

OK

redis 127.0.0.1:6379> lset mylist4 -2 "five"

OK

redis 127.0.0.1:6379> lrange mylist4 0 -1

1) "four"

2) "five"

3) "three"

redis 127.0.0.1:6379>

在此处我们依次插入了 one,two,three,然后将标是 0 的值设置为 four,再将下标是-2的值设

置为 five。

5.lrem

从key对应 list 中删除 count 个和 value 相同的元素。

阅读剩余部分

相关阅读 >>

什么是Redis

Redis介绍分布式数据库cap原理

Redis的五大用途你都知道么

关于Redis原子计数器incr,防止并发请求

使用Redis完成排行榜系统

使用Redis保存用户会话session详解

Redis三种部署方案图文详解

Redis是什么数据库?

Redis数据量过大怎么办

Redis和mysql一般怎么配合

更多相关阅读请进入《Redis》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...