最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

redis list類型命令的實現(xiàn)

 更新時間:2023年07月20日 15:10:53   作者:不想睡覺的橘子君  
本文主要介紹了redis list類型命令的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

redis的list類型,可以存儲雙向鏈表作為value,key保留有head和tail指針可以指向雙向鏈表的頭和尾,因此可以直接從頭或尾對list進行操作。
全部命令如下:

127.0.0.1:6379> help @list
? BLMOVE source destination LEFT|RIGHT LEFT|RIGHT timeout
? summary: Pop an element from a list, push it to another list and return it; or block until one is available
? since: 6.2.0
? BLMPOP timeout numkeys key [key ...] LEFT|RIGHT [COUNT count]
? summary: Pop elements from a list, or block until one is available
? since: 7.0.0
? 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 an element from a list, push it to another list and return it; or block until one is available
? since: 2.2.0
? LINDEX key index
? summary: Get an element from a list by its index
? since: 1.0.0
? LINSERT key BEFORE|AFTER pivot element
? summary: Insert an element before or after another element in a list
? since: 2.2.0
? LLEN key
? summary: Get the length of a list
? since: 1.0.0
? LMOVE source destination LEFT|RIGHT LEFT|RIGHT
? summary: Pop an element from a list, push it to another list and return it
? since: 6.2.0
? LMPOP numkeys key [key ...] LEFT|RIGHT [COUNT count]
? summary: Pop elements from a list
? since: 7.0.0
? LPOP key [count]
? summary: Remove and get the first elements in a list
? since: 1.0.0
? LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len]
? summary: Return the index of matching elements on a list
? since: 6.0.6
? LPUSH key element [element ...]
? summary: Prepend one or multiple elements to a list
? since: 1.0.0
? LPUSHX key element [element ...]
? summary: Prepend an element to a list, only if the list exists
? since: 2.2.0
? LRANGE key start stop
? summary: Get a range of elements from a list
? since: 1.0.0
? LREM key count element
? summary: Remove elements from a list
? since: 1.0.0
? LSET key index element
? summary: Set the value of an element in a list by its index
? since: 1.0.0
? LTRIM key start stop
? summary: Trim a list to the specified range
? since: 1.0.0
? RPOP key [count]
? summary: Remove and get the last elements in a list
? since: 1.0.0
? RPOPLPUSH source destination
? summary: Remove the last element in a list, prepend it to another list and return it
? since: 1.2.0
? RPUSH key element [element ...]
? summary: Append one or multiple elements to a list
? since: 1.0.0
? RPUSHX key element [element ...]
? summary: Append an element to a list, only if the list exists
? since: 2.2.0

下面示例如下:

  • lpush:lpush key e1 e2 e3…將數(shù)據(jù)從頭那里推入list
  • lpop:lpop key,將數(shù)據(jù)從head彈出

這樣2個同向的命令組合起來,可以實現(xiàn)一個隊列。

反向的命令組合起來,可以實現(xiàn)一個棧。

127.0.0.1:6379> lpush k1 a b c d e
(integer) 5
127.0.0.1:6379> lpop k1
"e"
127.0.0.1:6379> lpop k1
"d"

lrange :lrange key start end,展示key對應(yīng)的從下標(biāo)start到end的所有數(shù)據(jù)

127.0.0.1:6379> lrange k1 0 -1
1) "c"
2) "b"
3) "a"

lindex:lindex key index ,返回key對應(yīng)的List指定index位置的值

127.0.0.1:6379> lrange k1 0 -1
1) "f"
2) "e"
3) "d"
4) "c"
5) "b"
6) "a"
127.0.0.1:6379> lindex k1 1
"e"

lset:lset key index value,在key對應(yīng)的list中的指定下標(biāo)處替換為value

127.0.0.1:6379> lset k1 3 x
OK
127.0.0.1:6379> lrange k1 0 -1
1) "f"
2) "e"
3) "d"
4) "x"
5) "b"
6) "a"

lrem:lrem key num target,刪除key對應(yīng)的list中的target元素,如果num大于0,從head開始刪num個。如果num小于0,從tail開始刪abs(num)個

127.0.0.1:6379> lrange k3 0 -1
 1) "d"
 2) "6"
 3) "a"
 4) "5"
 5) "c"
 6) "4"
 7) "a"
 8) "3"
 9) "b"
10) "2"
11) "a"
12) "1"
127.0.0.1:6379> lrem k3 2 a
(integer) 2
127.0.0.1:6379> lrange k3 0 -1
 1) "d"
 2) "6"
 3) "5"
 4) "c"
 5) "4"
 6) "3"
 7) "b"
 8) "2"
 9) "a"
10) "1"

linsert:linsert key before/after element value,在key對應(yīng)的list中,在元素element(不是下標(biāo))之前或者之后,添加value

127.0.0.1:6379> lrange k3 0 -1
 1) "d"
 2) "6"
 3) "5"
 4) "c"
 5) "4"
 6) "3"
 7) "b"
 8) "2"
 9) "a"
10) "1"
127.0.0.1:6379> linsert k3 after 6 a
(integer) 11
127.0.0.1:6379> lrange k3 0 -1
 1) "d"
 2) "6"
 3) "a"
 4) "5"
 5) "c"
 6) "4"
 7) "3"
 8) "b"
 9) "2"
10) "a"
11) "1"

llen:llen key,返回長度
redis的List類型有很多關(guān)于下標(biāo)的操作,也可以將其抽象為一個數(shù)組來使用。

127.0.0.1:6379> llen k3
(integer) 10

blpop:blpop key time,彈出指定key對應(yīng)的list中的一個元素,如果list沒有元素或者不存在key對應(yīng)的這個list,則阻塞等待time指定的時間,0表示一直等待,單位是s。

127.0.0.1:6379> blpop k1 0

阻塞期間如果list有了元素,則會中斷阻塞并彈出

127.0.0.1:6379> blpop k1 0
1) "k1"
2) "a"
(35.77s)

ltrim:ltrim key start end,刪除key對應(yīng)的list start和end之外的兩端的元素

127.0.0.1:6379> lrange k4 0 -1
1) "f"
2) "e"
3) "d"
4) "c"
5) "b"
6) "a"
127.0.0.1:6379> ltrim k4 1 -2
OK
127.0.0.1:6379> lrange k4 0 -1
1) "e"
2) "d"
3) "c"
4) "b"

到此這篇關(guān)于redis list類型命令的實現(xiàn)的文章就介紹到這了,更多相關(guān)redis list類型內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • redis 交集、并集、差集的具體使用

    redis 交集、并集、差集的具體使用

    這篇文章主要介紹了redis 交集、并集、差集的具體使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Redis集群擴容的實現(xiàn)示例

    Redis集群擴容的實現(xiàn)示例

    本文介紹了在虛擬機上新建Redis集群,并將新增節(jié)點加入現(xiàn)有集群,通過配置文件和`redis-cli`命令,成功實現(xiàn)了Redis集群的擴容,感興趣的可以了解一下
    2025-02-02
  • 從MySQL到Redis的簡單數(shù)據(jù)庫遷移方法

    從MySQL到Redis的簡單數(shù)據(jù)庫遷移方法

    這篇文章主要介紹了從MySQL到Redis的簡單數(shù)據(jù)庫遷移方法,注意Redis數(shù)據(jù)庫基于內(nèi)存,并不能代替?zhèn)鹘y(tǒng)數(shù)據(jù)庫,需要的朋友可以參考下
    2015-06-06
  • Redis過期鍵刪除策略解讀

    Redis過期鍵刪除策略解讀

    Redis通過惰性刪除策略和定期刪除策略來管理過期鍵,惰性刪除策略在鍵被訪問時檢查是否過期并刪除,節(jié)省CPU開銷但可能導(dǎo)致過期鍵滯留,定期刪除策略定期掃描并刪除過期鍵,保證數(shù)據(jù)庫干凈但可能影響性能,Redis默認同時使用兩種策略
    2025-01-01
  • Redis設(shè)置密碼保護的實例講解

    Redis設(shè)置密碼保護的實例講解

    今天小編就為大家分享一篇Redis設(shè)置密碼保護的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • 關(guān)于redis Key淘汰策略的實現(xiàn)方法

    關(guān)于redis Key淘汰策略的實現(xiàn)方法

    下面小編就為大家?guī)硪黄P(guān)于redis Key淘汰策略的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • spring?boot集成redis基礎(chǔ)入門實例詳解

    spring?boot集成redis基礎(chǔ)入門實例詳解

    redis在spring?boot項目開發(fā)中是常用的緩存套件,常見使用的是spring-boot-starter-data-redis,這篇文章主要介紹了spring?boot集成redis基礎(chǔ)入門,本文結(jié)合實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-10-10
  • Redis AOF文件損壞報錯的完整修復(fù)方案

    Redis AOF文件損壞報錯的完整修復(fù)方案

    文章提供了三種修復(fù)Redis AOF持久化文件損壞的方法,方法一:備份損壞文件,使用官方工具修復(fù);方法二:修改配置讓Redis忽略損壞的文件尾部;方法三:如果是Redis且混合AOF格式,使用相同修復(fù)命令,每種方法都有詳細步驟,確保修復(fù)后Redis可以正常啟動,需要的朋友可以參考下
    2026-04-04
  • muduo源碼分析之TcpServer模塊詳細介紹

    muduo源碼分析之TcpServer模塊詳細介紹

    這篇文章主要介紹了muduo源碼分析之TcpServer模塊,本文通過實例圖文相結(jié)合給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • Redis 7持久化RDB和AOF的原理機制講解(圖文教程)

    Redis 7持久化RDB和AOF的原理機制講解(圖文教程)

    Redis是一個基于內(nèi)存的數(shù)據(jù)庫,由于內(nèi)存的易失性(斷電后數(shù)據(jù)會丟失),Redis提供了持久化機制:將內(nèi)存中的數(shù)據(jù)保存到磁盤中,確保數(shù)據(jù)在Redis服務(wù)重啟或崩潰后能夠恢復(fù),通過持久化,可以避免數(shù)據(jù)丟失,提高數(shù)據(jù)的可靠性,Redis提供兩種持久化方式:RDB和AOF
    2026-01-01

最新評論

威信县| 黎川县| 天门市| 太仆寺旗| 大厂| 松阳县| 和林格尔县| 桂东县| 资兴市| 黄山市| 蒙山县| 紫云| 墨竹工卡县| 东至县| 班戈县| 华阴市| 东台市| 德保县| 资溪县| 紫阳县| 南召县| 鱼台县| 永仁县| 罗平县| 普宁市| 安阳市| 苗栗县| 浠水县| 五莲县| 镇原县| 大足县| 白朗县| 波密县| 屏山县| 高阳县| 苏尼特左旗| 花垣县| 昭觉县| 蓝山县| 肃宁县| 乌鲁木齐县|