雷迪斯2
Aug 14, 2024 pm 05:28 PMRedis - 清單、集合和 HashMap
這是上一篇部落格的延續
除了鍵值對之外,還有其他 3 種資料型別可用
清單
此資料結構類似 Python 中的列表或 Javascript 或 C# 中的陣列。它們可用於保存最近使用過的物品。常見的操作有;
Operations | Explanations | Examples | Further Explanation |
---|---|---|---|
LPUSH | Adds an Item to the beginning of the list | LPUSH friends "Sophia" | similar to Array.unshift in javascript |
LRANGE | Get all the items in a list | LRANGE friends 0 -1 | similiarly a list in python 0 is the first item and -1 is the last item |
RPUSH | Adds an item to the end of the list | RPUSH friends "Poe" | similar to Array.push in javascript |
LPOP | Removes an item from the start of the list | LPOP friends "Poe" | Will return 1 if Poe exists in the list and 0 otherwise |
RPOP | Removes an item from the end of the list | RPOP friends "Sophia" | Will return 1 if Sophia exists in the list and 0 otherwise |
套
僅包含唯一項目的資料結構。類似 Python 中的集合、Javascript 中的集合和 C# 中的 HashSet。常見操作包括;
Operations | Explanations | Examples | Further Explanation |
---|---|---|---|
SADD | Adds a value to the set | SADD colors "pink" | |
SMEMBERS | returns the members of the set | SMEMBERS colors | will return all the items in the set colors |
SREM | Removes members of the set | SREM colors "pink" | Will return 1 if pink exists in the list and 0 otherwise |
哈希圖
雜湊圖是一組鍵值對。然而,哈希圖不能嵌套。讓我們來看一個有姓名、電子郵件和電話號碼的人的案例場景
HSET person name "Joe" # Adds the key-value pair {name : joe} to the hashmap HSET person email "Joe@joe.com" # Adds the key-value pair {email : Joe@joe.com} to the hashmap HSET person phone_number "+2345656655413" # Adds the key-value pair {number : ....} to the hashmap
登入後複製
HGET 指令可用來取得雜湊映射中特定鍵的值
HGET person name # returns "Joe"
登入後複製
HGETALL指令hashmap中的所有鍵值對
HGETALL person 1) "name" 2) "Joe" 3) "email" 4) "Joe@joe.com" 5) "phone_number" 6) "+2345656655413"
登入後複製
HDEL 指令透過鍵刪除鍵值對
HDEL person name # removes {name : joe}
登入後複製
HEXISTS 指令檢查雜湊集中是否存在某個鍵
HEXISTS person name # returns 0 because we've deleted it before
登入後複製
這些是開發人員需要了解的大部分基本命令。
常見面試問題
Redis 的完整意義是什麼? :Redis 代表遠端字典伺服器
Redis 與 MySQL 等傳統資料庫有何不同? :Redis 在主記憶體中運行,具有快速存取值的基本操作,不像 SQL 駐留在磁碟上並具有廣泛的增刪改查操作
Redis 在資料大小和類型方面有哪些限制? :Redis 旨在保存適合機器記憶體的值。它不適合具有連接的複雜關係模型或建立大型 blob
如何使用 Redis 在分散式環境中處理快取? :透過將 Redis 實例設定為資料庫前面的快取層來處理快取。使用一致性雜湊來分配快取節點上的金鑰,確保負載分佈均勻並減少快取未命中
什麼時候應該在 Redis 中使用列表資料類型? :清單非常適合持久原子佇列、作業佇列、日誌、緩衝區和許多其他用例
以上是雷迪斯2的詳細內容。更多資訊請關注PHP中文網其他相關文章!
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章
擊敗分裂小說需要多長時間?
3 週前
By DDD
倉庫:如何復興隊友
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前
By 尊渡假赌尊渡假赌尊渡假赌
公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?
3 週前
By 王林

熱門文章
擊敗分裂小說需要多長時間?
3 週前
By DDD
倉庫:如何復興隊友
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前
By 尊渡假赌尊渡假赌尊渡假赌
公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?
3 週前
By 王林

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)