redis key設計技巧

來源:互聯網
上載者:User

標籤:

1: 把表名轉換為key首碼 如, user:

2: 第2段放置用於區分區key的欄位--對應mysql中的主鍵的列名,如userid

3: 第3段放置主索引值,如2,3,4...., a , b ,c

4: 第4段,寫要儲存的列名

 

使用者表 user  , 轉換為key-value儲存

userid

username

passworde

email

9

Lisi

1111111

[email protected]

 

set user:userid:9:username lisi

set user:userid:9:password 111111

set user:userid:9:email   [email protected]

 

keys user:userid:9*

 

2注意:

在關係型資料中,除主鍵外,還有可能其他列也步驟查詢,

如上表中, username也是極頻繁查詢的,往往這種列也是加了索引的.

 

轉換到k-v資料中,則也要相應的產生一條按照該列為主的key-value

set user:username:lisi:uid  9 

 

這樣,我們可以根據username:lisi:uid ,查出userid=9,

再查user:userid:9:password/email...

完成了根據使用者名稱來查詢使用者資訊

 

redis key設計技巧

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.