get

读单行数据

  1. /**
  2. * Get value
  3. * @param {String} tableName
  4. * @param {Object} args
  5. * {Buffer} args.hashKey required
  6. * {Buffer} args.sortKey required
  7. * {Number} args.timeout(ms) optional
  8. * @param {Function} callback
  9. * @throws{InvalidParamException} callback is not function
  10. */
  11. client.get(
  12. tableName,
  13. args,
  14. function(err, result){
  15. // if get operation succeed, err will be null,
  16. // result.hashKey is hashKey, result.sortKey is sortKey, result.value is value
  17. // else err will be instance of PException, result will be null
  18. }
  19. );
  • get操作的必填参数有表名,hashKey,sortKey和callback
  • hashKey,sortKey和value都是Buffer对象,这与pegasus服务端key与value均为byte的语义保持一致
  • 超时时间为可选参数,默认为创建客户端时设定的超时时间
  • 当读操作成功时,callback的err为空,result.value为读到的值
  • 当读操作失败时,callback的result为空
  • 客户端不认为读不到值时错误,因此当读不到值时,err仍为空,result.value为Buffer('')