redis-list-objects
v0.10.0
Published
store and query json objects in redis lists
Downloads
2
Readme
store and query json objects in redis lists
installation
install package itself with:
npm install redis-object-store
module also depends on redis
:
npm install redis
you maybe want to use hiredis
too:
npm install hiredis
usage
// examples/example-1.js
var RedisObjectStore = require ('redis-object-store'),
redis = require ('redis');
var redisClient = redis.createClient ();
var store = new RedisObjectStore ('test', redisClient);
var doc = {
foo: 'foo',
bar: 1
};
store.insert (doc, function (err) {
store.query ({
foo: 'foo'
}, function (err, result) {
console.log (result); // -> [{foo:"foo",bar:1}]
});
});
interface
.constructor (name:String, redis:RedisClient, [options])
where options
follows the schema:
options = {
blockSize: 100,
serialize: function (object) {
return JSON.stringify (object);
},
parse: function (string) {
return JSON.parse (string);
}
}
.insert (documents, [function(err)])
documents
may be single object as well as array of objects
.query ([mongodbQuery], function(err, result)]
mongodbQuery
is parsed by sift
internals
module store inserted objects in redis list as follow:
this.redis.rpush (this.name, this.serialize(document))
module fetches documents from redis as follow:
this.redis.lrange (this.name, 0, length, function (err, result) {
var parsedResults = [],
sifted = sift (mongodbQuery);
results.forEach (function(data){
parsedResults.push (this.parse(data));
});
callback (err, sifted(parsedResults));
});