node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


Tag management system backed by Redis


rtags is a tag management system for node.js, backed by Redis. This module could be used to storage tags of blogs, commodities, photographs, individuals in the social web, etc.

    $ npm install rtags

The first thing you'll want to do is create a Tag instance, which allows you to pass a key, used for namespacing within Redis so that you may have several tags in the same db.

var tag = rtags.createTag('blogs');

rtags acts against string separated with ','. The following example uses an array for our "database", containing some strings, which we add to rtags by calling Tag#add() padding the body of text and an id of some kind, in this case the index.

var strs = [];
strs.forEach(function(str, i){ tag.add(str, i); });

To perform a query on an id, simply invoke Tag#queryID() with a string and pass a callback, which receives an array of ids when present, or an empty array otherwise.

  .queryID(id = '3')
  .end(function(err, ids){
    if (err) throw err;
    console.log('Tags for "%s":', id);
    var tags = ids.join(' ');
    console.log('  - %s', tags);

The previous example would yield the following output:

Tags for "3":
  - linux kernel linus 1991

To perform a query on two objects to find out the tags they both have, also invoke Tag#queryID(), but with two strings and a callback.

  .queryID(id1 = '3', id2 = '4')
  .end(function(err, ids){
    if (err) throw err;
    console.log('Tags for "%s" and "%s" both have:', id1, id2);
    var tags = ids.join(' ');
    console.log('  - %s', tags);

The previous example would yield the following output:

Tags for "3" and "4" both have:
  - kernel linux

To perform a query on tags, simply invoke Tag#queryTag(), with tags separated with ',' and a callback.

  .queryTag(tags = 'music,food')
  .end(function(err, ids){
    if (err) throw err;
    console.log('The objects own the "%s" tags:', tags);
    var id = ids.join(' ');
    console.log('  - %s', id);

The previous example would yield the following output:

The objects own the "music,food" tags:
  - 0 1
Tag#add(tags, id[, fn])
Tag#queryID(id, fn)
Tag#queryID(id1, id2, fn)
Tag#queryTag(tags, fn)
Tag#delTag(tags, id[, fn])
Tag#remove(id[, fn])


var tag = rtags.createTag('blogs');
tag.add('linux,kernel', '0');
tag.add('linux,linus', '1');
tag.queryID('0').end(function(err, ids){});
tag.queryID('0', '1').end(function(err, ids){});
tag.queryTag('linux,linus').end(function(err, ids){});
tag.delTag('linux', '0');

Running examples:

$ git clone
$ cd Rtags/test
$ node index.js

Copyright (c) 2012, LiXin,

Author: LiXin