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