redis初學建表問題

來源:互聯網
上載者:User
假設目前有mysql表article結構為
id
title標題
info內容
tags標籤id集合
status狀態(-1,0,1,2)
atime添加時間
utime更新時間
ptime發布時間
需求按(標籤/狀態)擷取文章根據(添加/更新/發布)時間排序
此時redis表應當如何設計?
目前的想法是
string類型
article:title:{id}
article:info:{id}
article:tags:{id}
article:status:{id}
article:atime:{id}
article:utime:{id}
article:ptime:{id}
set類型
全部集合:article:list
根據狀態分開儲存集合:article:status:{-1/0/1/2}
根據標籤分開儲存集合article:tag:{tag_id}

使用類似sort article:tag:1 by article:atime:*來獲得排序,這樣設計是否合理?

還有一個問題,嘗試做搜尋的時候,使用
zrangebylex article:status:0 [f (g
結果報錯
ERR unknown command 'zrangebylex'
是什麼原因?

回複內容:

假設目前有mysql表article結構為
id
title標題
info內容
tags標籤id集合
status狀態(-1,0,1,2)
atime添加時間
utime更新時間
ptime發布時間
需求按(標籤/狀態)擷取文章根據(添加/更新/發布)時間排序
此時redis表應當如何設計?
目前的想法是
string類型
article:title:{id}
article:info:{id}
article:tags:{id}
article:status:{id}
article:atime:{id}
article:utime:{id}
article:ptime:{id}
set類型
全部集合:article:list
根據狀態分開儲存集合:article:status:{-1/0/1/2}
根據標籤分開儲存集合article:tag:{tag_id}

使用類似sort article:tag:1 by article:atime:*來獲得排序,這樣設計是否合理?

還有一個問題,嘗試做搜尋的時候,使用
zrangebylex article:status:0 [f (g
結果報錯
ERR unknown command 'zrangebylex'
是什麼原因?

zrangebylex需要redis >= 2.8.9

sort article:tag:1 by article:atime:* 這句話是獲得添加時間排序的標籤為1的文章id排序吧?這設計可行

string類型的話不太推薦,會造成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.