Posted By

alejandromg on 07/08/11


Tagged

javascript redis nodejs asyncronus


Versions (?)

Redis clean


 / Published in: JavaScript
 

Delete all your Redis keys with nodejs, through the CLI.

  1. /*
  2. By. Alejandro Morales
  3. @_alejandromg
  4. El Siguiente script elimina todas las 'Keys' de una BDD Redis
  5. Peligrosa en las manos equivocadas. ��til? Si.
  6. */
  7. process.stdin.resume();
  8. process.stdin.setEncoding('utf8');
  9. console.log('\x1B[1;33m�¿Borrar? (Y/n)\x1B[0m ');
  10. function trim(stringToTrim) {
  11. return stringToTrim.replace(/^\s+|\s+$/g,"");
  12. }
  13. process.stdin.on('data', function (chunk) {
  14. chunk = trim(chunk);
  15. if (chunk == "Y") {
  16. var client = require("redis").createClient();
  17. client.keys("*", function (err, keys) {
  18. keys.forEach(function (key, pos) {
  19. client.del(key, function(err, o) {
  20. if (err) {
  21. console.error('No se elimino: ' + key);
  22. }
  23. else {
  24. console.log('Se borro: ' + key);
  25. }
  26. if (pos === (keys.length - 1)) {
  27. client.quit();
  28. }
  29. });
  30. });
  31. });
  32. } else { console.log('No v�¡lido. Saliendo\n'); }
  33. process.kill(process.pid, 'SIGHUP');
  34. });

Report this snippet  

You need to login to post a comment.