subquery.js 541 B

12345678910111213141516171819
  1. var client = require("redis").createClient();
  2. function print_results(obj) {
  3. console.dir(obj);
  4. }
  5. // build a map of all keys and their types
  6. client.keys("*", function (err, all_keys) {
  7. var key_types = {};
  8. all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos
  9. client.type(key, function (err, type) {
  10. key_types[key] = type;
  11. if (pos === all_keys.length - 1) { // callbacks all run in order
  12. print_results(key_types);
  13. }
  14. });
  15. });
  16. });