Functions for work with redis like mongodb. And sync mongo with redis. This module provide to write, read docs in redis like mongo, use collections and not only string fields.
You can store JSON object like some one:
{
str: "some string",
num: 1,
subDoc: {
created : new Date(),
rules: ['some string', 'some string 2']
},
floatValue: 9.9,
nullValue: null
}
var redis = require('redis'),
rc = redis.createClient();
For example store document into collection test_collection
with id 51e512352cb6640403695121
exRedis.write(rc, 'test_collection', '51e512352cb6640403695121', {
str: "some string",
num: 1,
subDoc: {
created : new Date(),
rules: ['some string', 'some string 2'],
testInc: 1
},
floatValue: 9.9,
nullValue: null
}, callback);
exRedis.read(rc, 'test_collection', '51e512352cb6640403695121', function(err, doc){});
exRedis.find(rc, 'test_collection', function(err, documents){});
exRedis.remove(rc, 'test_collection', '51e512352cb6640403695121', function(err){});
exRedis.inc(rc, 'test_collection', '51e512352cb6640403695121', 'subDoc.testInc', 1, function(err){});
exRedis.version(rc, 'test_collection', function(err, version){});
exRedis.setVersion(rc, 'test_collection', versionValue, function(err, version){});
exRedis.mongo.sync({
db: db, // Mongo native driver database
collection: 'test', // Collection name
defaultVersion : 10000 // Default value for version of collection data
},{
connection: rc, // Redis driver connection
collection: 'test', // Redis collection name
defaultVersion : 0 // Default value of version of collection data
}, function(err, count, fromTo){});
count
- count of transferred documents
fromTo
- side of transfer, may be mongodb -> redis
, redis -> mongodb
or none
if versions is same