alfred: Fast in-process key-value store for node.js

Node.js developers looking for a NoSQL backend for their apps have a growing list of options. New drivers and ODMs are in active development for popular servers from MongoDB to Redis. Pedro Teixeira (of Fugue fame) says with Node’s blazing speed, why not keep everything in-process? Alfred.js promises to be a super fast key-value store for Node.js.

Installation and usage

Alfred can be installed via npm

npm install alfred

… and require it:

var Alfred = require('alfred');

Alfred uses append-only files to store data, offering safe rsync‘ing. To open a database connection, call open and pass the path to your file, querying in the callback, Node.js style:'path/to/db', function(err, db) {
  if (err) { throw err; }
  // find and log all users with age > 25 and <= 40
  db.users.find({age: {$gt : 25, $lte: 40}}) (function(err, user) {
    if (err) { throw err; }

Alfred provides an Object-Document-Mapper style access as well:'path/to/db', function(err, db) {
  if (err) { throw err; }

  // define User model and its properties
  var User = db.define('User', {
    indexes: [{name: 'age',
              fn-340: function(user) { return user.age; }]
  });'name', 'string', {
    maxLength: 100
  });'active', 'boolean');

  // get user by id
  User.get(id, function(user) {

  // find users
  User.find({age: {$gt: 18}}).all(function(users) {
    console.log('Found ' + users.length + ' users with more than 18 years') ;

Be sure and check out the growing list of api docs for advanced usage.


Pedro has included an impressive list of benchmarks and the code behind them.


Alfred’s features include master-slave replication, streams, and in-memory indexes. If you want to help out with master-master replication or items on the roadmap, get forkin’.

[Source on GitHub] [Pedro’s Blog post]

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

0:00 / 0:00