diff --git a/chap8-redis/populate_couch.js b/chap8-redis/populate_couch.js index 1a9c393..fb84e0e 100644 --- a/chap8-redis/populate_couch.js +++ b/chap8-redis/populate_couch.js @@ -19,8 +19,7 @@ var http = require('http'), redis = require('redis'), - // database clients - couchClient = http.createClient(5984, 'localhost'), + // database client redisClient = redis.createClient(6379); /** @@ -62,11 +61,14 @@ function trackLineCount( increment ) { */ function postDoc( url, docsString, count ) { - var request = couchClient.request( - 'POST', - url, - { 'Content-Type' : 'application/json' }); - request.end( docsString ); + var request = http.request( + { hostname : 'localhost', + port: 5984, + path: url, + method: 'POST', + headers: { + 'Content-Type': 'application/json'} + }); request.on('response', function(response) { if(response.statusCode == 201) @@ -75,6 +77,8 @@ function postDoc( url, docsString, count ) { on('error', function(e) { console.log('postDoc Got error: ' + e.message); }); + request.write(docsString) + request.end(); }; /* @@ -95,7 +99,11 @@ function postDoc( url, docsString, count ) { function populateBands() { // First, create the couch database - couchClient.request('PUT', couchDBpath).end(); + http.request( + { hostname : 'localhost', + port: 5984, + path: couchDBpath, + method: 'PUT'}).end(); redisClient.keys('band:*', function(error, bandKeys) { totalBands = bandKeys.length; diff --git a/chap8-redis/pre_populate.js b/chap8-redis/pre_populate.js index 6102830..9bd2457 100644 --- a/chap8-redis/pre_populate.js +++ b/chap8-redis/pre_populate.js @@ -46,16 +46,17 @@ function trackLineCount() { */ function populateRedis() { csv(). - fromPath( tsvFileName, { delimiter: '\t', quote: '' }). - on('data', function(data, index) { + from.path( tsvFileName, { delimiter: '\t', quote: '' }). + on('record', function(record, index) { var - artist = data[2], - band = data[3], - roles = buildRoles(data[4]); + artist = record[2], + band = record[3], + roles = buildRoles(record[4]); if( band === '' || artist === '' ) { trackLineCount(); return true; - } + } + //console.log('#'+index+' '+JSON.stringify(record)); redis_client.sadd('band:' + band, artist); roles.forEach(function(role) { redis_client.sadd('artist:' + band + ':' + artist, role);