testRedis2MySql.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. require('../extensions/function_extend.js');
  3. var co = require('co');
  4. var R2M = require('../framework/lib/Redis2Mysql.js');
  5. var objR2m = new R2M('cUser', 'Web', 'Web');
  6. co(function*() {
  7. //var where = {userId:13501489295};
  8. //var row = objR2m.getRow(where);
  9. //console.log(row);
  10. //var where = {enable:1};
  11. //// var where = {userId:13501489295};
  12. //var data = yield objR2m.getAll(where);
  13. //console.log(data);
  14. var userId = 12345;
  15. where = {userId:userId};
  16. var row = yield objR2m.getRow(where);
  17. if (!row) {
  18. console.log('addObject');
  19. var data = {userId:userId, userName:'MyTest', enable:1, anotherPwd:'another'};
  20. var result = yield objR2m.addObject(data);
  21. } else {
  22. console.log('updateObject');
  23. var data = {userName:'edddrwe11223', enable:1, anotherPwd:'another'};
  24. var where = {userId:userId};
  25. var result = yield objR2m.updateObject(data, where);
  26. console.log(result);
  27. console.log('replaceObject');
  28. var args = {userId:userId, userName:'edddrwe11', enable:1, anotherPwd:'another'};
  29. var result = yield objR2m.replaceObject(args);
  30. console.log(result);
  31. if (result.changedRows == 0) {
  32. console.log('delObject');
  33. var result = yield objR2m.delObject(where);
  34. console.log(result);
  35. }
  36. }
  37. setTimeout(function() {
  38. objR2m.close();
  39. }, 1000);
  40. console.log('end');
  41. return 2333;
  42. }).then(console.log, console.error);
  43. process.on('exit', function(code) {
  44. console.log('About to exit with code:', code);
  45. });