batchGet

读取一批数据

  1. /**
  2. * Batch Get value
  3. * @param {String} tableName
  4. * @param {Array} argsArray
  5. * {Buffer} argsArray[i].hashKey required
  6. * {Buffer} argsArray[i].sortKey required
  7. * {Number} argsArray[i].timeout(ms) optional
  8. * @param {Function} callback
  9. * @throws{InvalidParamException} callback is not function
  10. */
  11. client.batchGet(
  12. tableName,
  13. argsArray,
  14. function(err, result){
  15. // err will be always be null, result is {'error': err, 'data': result} array
  16. // if batchGet[i] operation succeed, result[i].error will be null
  17. // result[i].data.hashKey is hashKey, result[i].data.sortKey is sortKey, result[i].data.value is value
  18. // else result[i].error will be instance of PException, result[i].data will be null
  19. }
  20. );
  • batchGet操作的必填参数为表名,hashKey数组,sortKey数组和callback
  • 与multiGet不同的是,batchGet支持读多个hashKey的值
  • batchGet将等待所有本次batch的所有get操作都返回结果后才返回
  • callback的err总是为null
  • callback的result是一个数组,result[i].error表示第i个get操作的出错情况,result[i].data表示第i个get操作的结果