https://cnodejs.org/topic/53ad78f2c3ee0b5820f74298
Follow,tag, and feed system are very suitable for using Redis to implement, take the tag system as an example: User Ltebean to add a label to Nodejs amazing is:
sadd user:ltebean:tag:amazing nodejssadd user:ltebean:item:nodejs amazing
A reverse relationship is saved in order to be able to check according to tag, and the following is the command of Redis:
Get all the Nodejs tags:
smembers user:ltebean:item:nodejs
Get all the item under tag amazing:
smembers user:ltebean:tag:amazing
Get the item with both a amazing tag and a Web label hit
sunion user:ltebean:tag:amazing user:ltebean:tag:web
Here is the API implemented by Nodejs:
Taggie.User(' Ltebean ').Item(' Bootstrap ').Addtag(' CSS ', function(Err,Res) {});Taggie.User(' Ltebean ').Item(' Bootstrap ').Addtag(' Web ', function(Err,Res) {});Taggie.User(' Ltebean ').Item(' jquery ').Addtag(' Web ', function(Err,Res) {});Taggie.User(' Ltebean ').Item(' jquery ').Addtag(' JS ', function(Err,Res) {});Taggie.User(' Ltebean ').Item(' Nodjs ').Addtag(' JS ', function(Err,Res) {});Taggie.User(' Ltebean ').Item(' jquery ').AllTags(function(Err,Res) {Console.Log("jquery s Tag:%s",Res); jquery ' s Tag:js,web});Taggie.User(' Ltebean ').Item().AllItems(function(Err,Res) {Console.Log("All Items:%s",Res); All Items:jquery,nodjs,bootstrap});Taggie.User(' Ltebean ').Tag(' Web ').AllItems(function(Err,Res){Console.Log(' Tagged with Web:%s ',Res); Tagged with web:jquery,bootstrap});Taggie.User(' Ltebean ').Tag().AllTags(function(Err,Res){Console.Log(' All Tags:%s ',Res); All Tags:js,web,css});Taggie.User(' Ltebean ').Tag([' Web ',' JS ']).Itemsbyinter(function(Err,Res){Console.Log(' Tagged with Web and js:%s ',Res); Tagged with web and js:jquerytaggie. "Ltebean" ([ ' web ' itemsbyunion (function ( Err,res) { Console.< Span class= "PLN" >log (res); //tagged with Web or js:jquery,nodjs,bootstrap
User follow and feed system implementation is similar, finally attached three items address: Taggie:https://github.com/ltebean/taggie user-graph:https://github.com/ Ltebean/user-graph Feedie:https://github.com/ltebean/feedie
Implementing Follow,tag,feed System with node plus Redis