Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions chap8-redis/populate_couch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ var
http = require('http'),
redis = require('redis'),

// database clients
couchClient = http.createClient(5984, 'localhost'),
// database client
redisClient = redis.createClient(6379);

/**
Expand Down Expand Up @@ -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)
Expand All @@ -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();
};

/*
Expand All @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions chap8-redis/pre_populate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down