src/index.js
function getStorageObj(client, namespace) {
    return {
        get: function(id, cb) {
            client.hget(namespace, id, function(err, res) {
                cb(err, res ? JSON.parse(res) : null);
            });
        },
        save: function(object, cb) {
            if (!object.id) {
                return cb(new Error('The given object must have an id property'), {});
            }

            client.hset(namespace, object.id, JSON.stringify(object), cb);
        },
        remove: function(id, cb) {
            client.hdel(namespace, [id], cb);
        },
        all: function(cb, options) {
            client.hgetall(namespace, function(err, res) {
                if (err) {
                    return cb(err);
                }

                var parsed,
                    array = [];

                for (var i in res) {
                    parsed = JSON.parse(res[i]);
                    res[i] = parsed;
                    array.push(parsed);
                }

                cb(null, options && options.type === 'object' ? res : array);
            });
        }
    };
}
function getStorageObj(client, namespace) {
    return {
        get: function(id, cb) {
            client.hget(namespace, id, function(err, res) {
                cb(err, res ? JSON.parse(res) : null);
            });
        },
        save: function(object, cb) {
            if (!object.id) {
                return cb(new Error('The given object must have an id property'), {});
            }

            client.hset(namespace, object.id, JSON.stringify(object), cb);
        },
        remove: function(id, cb) {
            client.hdel(namespace, [id], cb);
        },
        all: function(cb, options) {
            client.hgetall(namespace, function(err, res) {
                if (err) {
                    return cb(err);
                }

                var parsed,
                    array = [];

                for (var i in res) {
                    parsed = JSON.parse(res[i]);
                    res[i] = parsed;
                    array.push(parsed);
                }

                cb(null, options && options.type === 'object' ? res : array);
            });
        }
    };
}
function getStorageObj ( client , namespace ) { return { get : function ( id , cb ) { client . hget ( namespace , id , function ( err , res ) { cb ( err , res ? JSON . parse ( res ) : null ) ; } ) ; } , save : function ( object , cb ) { if ( ! object . id ) { return cb ( new Error ( 'The given object must have an id property' ) , { } ) ; } client . hset ( namespace , object . id , JSON . stringify ( object ) , cb ) ; } , remove : function ( id , cb ) { client . hdel ( namespace , [ id ] , cb ) ; } , all : function ( cb , options ) { client . hgetall ( namespace , function ( err , res ) { if ( err ) { return cb ( err ) ; } var parsed , array = [ ] ; for ( var i in res ) { parsed = JSON . parse ( res [ i ] ) ; res [ i ] = parsed ; array . push ( parsed ) ; } cb ( null , options && options . type === 'object' ? res : array ) ; } ) ; } } ; }
Function to generate a storage object for a given namespace

@param {Object} client The redis client
@param {String} namespace The namespace to use for storing in Redis
@returns {{get: get, save: save, all: all, allById: allById}}
Function to generate a storage object for a given namespace