Created
March 7, 2011 21:57
-
-
Save nathanhammond/859352 to your computer and use it in GitHub Desktop.
Simple script to get all Redis commands in a format that mranney/node_redis can use.
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 http = require('http'); | |
var fs = require('fs'); | |
var redisio = http.createClient(80, 'redis.io'); | |
function getCommands() { | |
var commandrequest = redisio.request('GET', '/commands.json', {'Host': 'redis.io'}); | |
commandrequest.end(); | |
var commandsfile = fs.createWriteStream('commands.json'); | |
commandrequest.on('response', function (response) { | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
commandsfile.write(chunk); | |
}); | |
response.on('end', function() { | |
fs.readFile('commands.json', 'utf8', function (err, res) { | |
process(JSON.parse(res)); | |
}); | |
}); | |
}); | |
} | |
function process(commands) { | |
var results = {}; | |
for (var command in commands) { | |
if (!results[commands[command].group]) { results[commands[command].group] = []; } | |
// Process 'em. | |
var processed = command.toLowerCase(); | |
if (processed.indexOf(' ') !== -1) { | |
continue; | |
// Camel Case! | |
var temp = processed.split(' '); | |
for (var i = 1; i < temp.length; i++) { | |
temp[i] = temp[i].charAt(0).toUpperCase() + temp[i].slice(1); | |
} | |
processed = temp.join(''); | |
} | |
results[commands[command].group].push(processed); | |
} | |
// Output pretty | |
var output = "[ \r\n"; | |
for (var group in results) { | |
output += " \/\/ " + group + "\r\n"; | |
output += " \"" + results[group].join('", "') + "\",\r\n" | |
} | |
output = output.slice(0, -3); | |
output += "\r\n]"; | |
console.log(output); | |
} | |
getCommands(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment