Last active
August 29, 2015 14:04
-
-
Save dignifiedquire/27a367d6727445824241 to your computer and use it in GitHub Desktop.
Streaming JSON to and from redis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "redis-streaming-test", | |
"version": "0.0.0", | |
"description": "", | |
"main": "redis.js", | |
"dependencies": { | |
"blocked": "^1.0.0", | |
"flow-parse": "^0.0.1", | |
"flow-stringify": "^0.0.1", | |
"hiredis": "^0.1.17", | |
"redis": "^0.11.0", | |
"redis-rstream": "^0.1.2", | |
"redis-stream": "^0.1.0", | |
"redis-wstream": "^0.2.5" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Redis = require('redis'); | |
var blocked = require('blocked'); | |
var client = Redis.createClient(); | |
var wStream = require('redis-wstream'); | |
var rStream = require('redis-rstream'); | |
var domain = require('domain'); | |
var stringify = require('flow-stringify'); | |
var parse = require('flow-parse'); | |
var fs = require('fs'); | |
blocked(function(ms) { | |
console.log('blocked: ' + ms || 0); | |
}); | |
JSON.parse(fs.readFileSync('./npm.json')); | |
var bootstrapData = { | |
'field1': { | |
my: 'nested' | |
}, | |
'field2': 'val2' | |
}; | |
function errHandler(err) { | |
if (err) { | |
console.error(err); | |
process.exit(1); | |
} | |
} | |
//var inputStream = stringify().stream(errHandler); | |
var inputStream = fs.createReadStream('./npm.json'); | |
var outputStream = parse().stream(errHandler); | |
var key = 'npm'; | |
inputStream | |
.pipe(wStream(client, key)) | |
.on('finish', function () { | |
console.log('finshed writing'); | |
rStream(client, key) | |
.pipe(outputStream) | |
// .on('data', function (chunk) { | |
// console.log(chunk, typeof chunk, chunk.toString()); | |
// }) | |
.on('end', function () { | |
console.log('finished reading'); | |
process.exit(); | |
}); | |
}); | |
//inputStream.write(bootstrapData); | |
//inputStream.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment