Windshaft-cartodb/tools/reset_styles
2012-09-21 12:58:34 +02:00

36 lines
860 B
JavaScript
Executable File

#!/usr/bin/env node
// Reset redis-stored XML styles so that they are regenerated
// from CartoCSS on next tile request
var redis = require('redis')
var REDIS_PORT = 6379; // TODO: make a parameter
var dbnum = 0;
var client = redis.createClient(REDIS_PORT, 'localhost');
client.on('connect', function() {
client.select(dbnum);
client.keys('map_style|*', function(err, matches) {
processNext = function() {
if ( ! matches.length ) process.exit(0);
var k = matches.shift();
console.log("Resetting XML in key: " + k);
client.get(k, function(err, val) {
if ( err ) throw err;
val = JSON.parse(val);
delete val.xml;
client.set(k, JSON.stringify(val), function() {
console.log("done with style " + k);
processNext();
});
});
}
processNext();
});
});