Redis-key Design Principles

Source: Internet
Author: User
Tags value store

Bookmark System CREATE TABLE book (BookID int,Title char (20) engine MyISAM charset Utf8;insert into book values (5, ' php Bible '),(6, ' Ruby Combat '),(7, ' MySQL Ops '),(8, ' Ruby Server-side programming 'CREATE TABLE tags (tid int,BookID int,Content char (20) engine MyISAM charset Utf8;insert into tags values (5, ' PHP '),(One, 5, ' WEB '),(6, ' WEB '),(6, ' Ruby '),(7, ' database '),(8, ' Ruby '),(8, ' server ');#both Web tags, and PHP, but also the label of the book, to use the connection querySelect* FROM tags innerJoinTags asT on Tags.bookid=t.Bookidwhere Tags. content= ' PHP ' and t.content= ' WEB '; switch to key-value store uses KV to store set book: 5:title ' php Bible 'Set Book: 6:title ' Ruby Combat 'Set Book: 7:title ' MySQL transport difficult 'Set Book: 8:title ' Ruby Server ' sadd tag:P HP 5sadd Tag: WEB 5 6sadd Tag:d Atabase 7sadd Tag: Ruby 6 8sadd Tag: SERVER 8Check: both PHP,and a Web book sinter tag.:P HP Tag:web#Check the intersection of the setCheck:php or Web-tagged book sunin tag:P HP Tag:Web Search: Contains Ruby,a book without web tags sdiff tag: Ruby Tag:web#Finding the difference setRedisKeyDesign Tips1: Convert the table name to the key prefix, such as Tag:2:2nd place the field for the Zone key-the column name corresponding to the primary key in MySQL,such as UserID3: The 3rd paragraph places the primary key value, such as 2,3,4 ...., A, B,C4:4th paragraph,write the column name to store user table users, convert to key-Value Store
--------------------------------------------------userid Username Passworde Email
--------------------------------------------------9 Lisi 1111111 [email protected]com
--------------------------------------------------Set User: Userid:9:username Lisiset User: Userid:9:password 111111Set User: userid:9:email [email protected]Comkeys User: userid:9*2 Note:In the relational data, in addition to the primary key, there may be other columns also step query,as in the table above, username is also very frequently queried, often this column is also indexed.Convert to K-V data, it is also necessary to generate a corresponding column based on the key-ValueSet User: Username:lisi:uid 9this, we can find userid=9 according to Username:lisi:uid,Check user again .: 9:password/email ...

Redis-key Design Principles

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.