blob: 2b703dc15f9bf4a8ee2eed434be000e05d71a32e [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pegasus | Node Client</title>
<link rel="stylesheet" href="/zh/assets/css/app.css">
<link rel="shortcut icon" href="/zh/assets/images/favicon.ico">
<link rel="stylesheet" href="/zh/assets/css/utilities.min.css">
<link rel="stylesheet" href="/zh/assets/css/docsearch.v3.css">
<script src="/assets/js/jquery.min.js"></script>
<script src="/assets/js/all.min.js"></script>
<script src="/assets/js/docsearch.v3.js"></script>
<!-- Begin Jekyll SEO tag v2.8.0 -->
<title>Node Client | Pegasus</title>
<meta name="generator" content="Jekyll v4.3.2" />
<meta property="og:title" content="Node Client" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="安装NodeJs客户端 项目地址:Pegasus NodeJS Client 下载并将客户端依赖添加到package.json中: npm install pegasus-nodejs-client --save 创建/关闭客户端 create let pegasusClient = require(&#39;pegasus-nodejs-client&#39;); /** * Create a client instance * @param {Object} configs * {Array} configs.metaServers required * {String} configs.metaServers[i] required * {Number} configs.operationTimeout(ms) optional * {Object} configs.log optional * @return {Client} client instance * @throws {InvalidParamException} */ client = pegasusClient.create({ metaServers: [&#39;127.0.0.1:34601&#39;, &#39;127.0.0.1:34602&#39;, &#39;127.0.0.1:34603&#39;], operationTimeout : 5000, log : log, }); metaServers为meta server地址列表,为必填项 operationTimeout为本次操作的超时时间,单位是毫秒,默认是1000ms log为日志库实例 我们使用日志库 log4js 默认使用的日志配置在log_config.js文件中,配置如下: let filename = &quot;./logs/&quot;+process.pid+&quot;/pegasus-nodejs-client.log&quot;; let logConfig = { appenders: { pegasus: { type: &quot;file&quot;, filename: filename, maxLogSize: 104857600, backups: 10 } }, categories: { default: { appenders: [&quot;pegasus&quot;], level: &quot;INFO&quot; } } }; 上述配置表示,会将错误级别等于及高于INFO级别的日志存储在文件中,每个日志文件最大100M,最多保留10个日志文件 若不想使用默认配置,则需要重新定义如上的logConfig对象,作为创建客户端时的log对象 当参数有误时,会抛出异常,停止后续操作" />
<meta property="og:description" content="安装NodeJs客户端 项目地址:Pegasus NodeJS Client 下载并将客户端依赖添加到package.json中: npm install pegasus-nodejs-client --save 创建/关闭客户端 create let pegasusClient = require(&#39;pegasus-nodejs-client&#39;); /** * Create a client instance * @param {Object} configs * {Array} configs.metaServers required * {String} configs.metaServers[i] required * {Number} configs.operationTimeout(ms) optional * {Object} configs.log optional * @return {Client} client instance * @throws {InvalidParamException} */ client = pegasusClient.create({ metaServers: [&#39;127.0.0.1:34601&#39;, &#39;127.0.0.1:34602&#39;, &#39;127.0.0.1:34603&#39;], operationTimeout : 5000, log : log, }); metaServers为meta server地址列表,为必填项 operationTimeout为本次操作的超时时间,单位是毫秒,默认是1000ms log为日志库实例 我们使用日志库 log4js 默认使用的日志配置在log_config.js文件中,配置如下: let filename = &quot;./logs/&quot;+process.pid+&quot;/pegasus-nodejs-client.log&quot;; let logConfig = { appenders: { pegasus: { type: &quot;file&quot;, filename: filename, maxLogSize: 104857600, backups: 10 } }, categories: { default: { appenders: [&quot;pegasus&quot;], level: &quot;INFO&quot; } } }; 上述配置表示,会将错误级别等于及高于INFO级别的日志存储在文件中,每个日志文件最大100M,最多保留10个日志文件 若不想使用默认配置,则需要重新定义如上的logConfig对象,作为创建客户端时的log对象 当参数有误时,会抛出异常,停止后续操作" />
<meta property="og:site_name" content="Pegasus" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2023-11-23T14:57:08+00:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="Node Client" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","dateModified":"2023-11-23T14:57:08+00:00","datePublished":"2023-11-23T14:57:08+00:00","description":"安装NodeJs客户端 项目地址:Pegasus NodeJS Client 下载并将客户端依赖添加到package.json中: npm install pegasus-nodejs-client --save 创建/关闭客户端 create let pegasusClient = require(&#39;pegasus-nodejs-client&#39;); /** * Create a client instance * @param {Object} configs * {Array} configs.metaServers required * {String} configs.metaServers[i] required * {Number} configs.operationTimeout(ms) optional * {Object} configs.log optional * @return {Client} client instance * @throws {InvalidParamException} */ client = pegasusClient.create({ metaServers: [&#39;127.0.0.1:34601&#39;, &#39;127.0.0.1:34602&#39;, &#39;127.0.0.1:34603&#39;], operationTimeout : 5000, log : log, }); metaServers为meta server地址列表,为必填项 operationTimeout为本次操作的超时时间,单位是毫秒,默认是1000ms log为日志库实例 我们使用日志库 log4js 默认使用的日志配置在log_config.js文件中,配置如下: let filename = &quot;./logs/&quot;+process.pid+&quot;/pegasus-nodejs-client.log&quot;; let logConfig = { appenders: { pegasus: { type: &quot;file&quot;, filename: filename, maxLogSize: 104857600, backups: 10 } }, categories: { default: { appenders: [&quot;pegasus&quot;], level: &quot;INFO&quot; } } }; 上述配置表示,会将错误级别等于及高于INFO级别的日志存储在文件中,每个日志文件最大100M,最多保留10个日志文件 若不想使用默认配置,则需要重新定义如上的logConfig对象,作为创建客户端时的log对象 当参数有误时,会抛出异常,停止后续操作","headline":"Node Client","mainEntityOfPage":{"@type":"WebPage","@id":"/clients/node-client"},"url":"/clients/node-client"}</script>
<!-- End Jekyll SEO tag -->
</head>
<body>
<div class="dashboard is-full-height">
<!-- left panel -->
<div class="dashboard-panel is-medium is-hidden-mobile pl-0">
<div class="dashboard-panel-header has-text-centered">
<a href="/zh/">
<img src="/assets/images/pegasus-logo-inv.png" style="width: 80%;">
</a>
</div>
<div class="dashboard-panel-main is-scrollable pl-6">
<aside class="menu">
<p class="menu-label">Pegasus产品文档</p>
<ul class="menu-list">
<li>
<a href="/zh/docs/downloads"
class="">
下载
</a>
</li>
</ul>
<p class="menu-label">编译构建</p>
<ul class="menu-list">
<li>
<a href="/zh/docs/build/compile-by-docker"
class="">
使用Docker完成编译(推荐)
</a>
</li>
<li>
<a href="/zh/docs/build/compile-from-source"
class="">
从源码编译
</a>
</li>
</ul>
<p class="menu-label">客户端库</p>
<ul class="menu-list">
<li>
<a href="/zh/clients/java-client"
class="">
Java客户端
</a>
</li>
<li>
<a href="/zh/clients/cpp-client"
class="">
C++客户端
</a>
</li>
<li>
<a href="https://github.com/apache/incubator-pegasus/tree/master/go-client"
class="">
Golang客户端
</a>
</li>
<li>
<a href="/zh/clients/python-client"
class="">
Python客户端
</a>
</li>
<li>
<a href="/zh/clients/node-client"
class="is-active">
NodeJS客户端
</a>
</li>
<li>
<a href="/zh/clients/scala-client"
class="">
Scala客户端
</a>
</li>
</ul>
<p class="menu-label">生态工具</p>
<ul class="menu-list">
<li>
<a href="/zh/docs/tools/shell"
class="">
Pegasus Shell 工具
</a>
</li>
<li>
<a href="https://github.com/pegasus-kv/admin-cli"
class="">
集群管理命令行
</a>
</li>
<li>
<a href="https://github.com/pegasus-kv/pegic"
class="">
数据访问命令行
</a>
</li>
</ul>
<p class="menu-label">用户接口</p>
<ul class="menu-list">
<li>
<a href="/zh/api/ttl"
class="">
TTL
</a>
</li>
<li>
<a href="/zh/api/single-atomic"
class="">
单行原子操作
</a>
</li>
<li>
<a href="/zh/api/redis"
class="">
Redis适配
</a>
</li>
<li>
<a href="/zh/api/geo"
class="">
GEO支持
</a>
</li>
<li>
<a href="/zh/api/http"
class="">
HTTP接口
</a>
</li>
</ul>
<p class="menu-label">高效运维</p>
<ul class="menu-list">
<li>
<a href="/zh/administration/deployment"
class="">
集群部署
</a>
</li>
<li>
<a href="/zh/administration/config"
class="">
配置说明
</a>
</li>
<li>
<a href="/zh/administration/rebalance"
class="">
负载均衡
</a>
</li>
<li>
<a href="/zh/administration/monitoring"
class="">
可视化监控
</a>
</li>
<li>
<a href="/zh/administration/rolling-update"
class="">
集群升级
</a>
</li>
<li>
<a href="/zh/administration/scale-in-out"
class="">
集群扩容缩容
</a>
</li>
<li>
<a href="/zh/administration/resource-management"
class="">
资源管理
</a>
</li>
<li>
<a href="/zh/administration/cold-backup"
class="">
冷备份
</a>
</li>
<li>
<a href="/zh/administration/meta-recovery"
class="">
元数据恢复
</a>
</li>
<li>
<a href="/zh/administration/replica-recovery"
class="">
Replica数据恢复
</a>
</li>
<li>
<a href="/zh/administration/zk-migration"
class="">
Zookeeper迁移
</a>
</li>
<li>
<a href="/zh/administration/table-migration"
class="">
Table迁移
</a>
</li>
<li>
<a href="/zh/administration/table-soft-delete"
class="">
Table软删除
</a>
</li>
<li>
<a href="/zh/administration/table-env"
class="">
Table环境变量
</a>
</li>
<li>
<a href="/zh/administration/remote-commands"
class="">
远程命令
</a>
</li>
<li>
<a href="/zh/administration/partition-split"
class="">
Partition-Split
</a>
</li>
<li>
<a href="/zh/administration/duplication"
class="">
跨机房同步
</a>
</li>
<li>
<a href="/zh/administration/compression"
class="">
数据压缩
</a>
</li>
<li>
<a href="/zh/administration/throttling"
class="">
流量控制
</a>
</li>
<li>
<a href="/zh/administration/experiences"
class="">
运维经验
</a>
</li>
<li>
<a href="/zh/administration/manual-compact"
class="">
Manual Compact功能
</a>
</li>
<li>
<a href="/zh/administration/usage-scenario"
class="">
Usage Scenario功能
</a>
</li>
<li>
<a href="/zh/administration/bad-disk"
class="">
坏盘检修
</a>
</li>
<li>
<a href="/zh/administration/whitelist"
class="">
白名单
</a>
</li>
<li>
<a href="/zh/administration/backup-request"
class="">
Backup Request
</a>
</li>
<li>
<a href="/zh/administration/hotspot-detection"
class="">
热点检测
</a>
</li>
</ul>
</aside>
</div>
</div>
<!-- main section -->
<div class="dashboard-main is-scrollable">
<nav class="navbar is-hidden-desktop">
<div class="navbar-brand">
<a href="/zh/" class="navbar-item">
<!-- Pegasus Icon -->
<img src="/assets/images/pegasus-square.png">
</a>
<div class="navbar-item">
<!--A simple language switch button that only supports zh and en.-->
<!--IF its language is zh, then switches to en.-->
<!--If you don't want a url to be relativized, you can add a space explicitly into the href to
prevents a url from being relativized by polyglot.-->
<a class="button is-light is-outlined is-inverted" href=" /clients/node-client"><strong>En</strong></a>
</div>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navMenu">
<!-- Appears in mobile mode only -->
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div class="navbar-menu" id="navMenu">
<div class="navbar-end">
<!--dropdown-->
<div class="navbar-item has-dropdown is-hoverable">
<a href=""
class="navbar-link ">
<span>
Pegasus产品文档
</span>
</a>
<div class="navbar-dropdown">
<a href="/zh/docs/downloads"
class="navbar-item ">
下载
</a>
</div>
</div>
<!--dropdown-->
<div class="navbar-item has-dropdown is-hoverable">
<a href=""
class="navbar-link ">
<span>
编译构建
</span>
</a>
<div class="navbar-dropdown">
<a href="/zh/docs/build/compile-by-docker"
class="navbar-item ">
使用Docker完成编译(推荐)
</a>
<a href="/zh/docs/build/compile-from-source"
class="navbar-item ">
从源码编译
</a>
</div>
</div>
<!--dropdown-->
<div class="navbar-item has-dropdown is-hoverable">
<a href=""
class="navbar-link ">
<span>
客户端库
</span>
</a>
<div class="navbar-dropdown">
<a href="/zh/clients/java-client"
class="navbar-item ">
Java客户端
</a>
<a href="/zh/clients/cpp-client"
class="navbar-item ">
C++客户端
</a>
<a href="https://github.com/apache/incubator-pegasus/tree/master/go-client"
class="navbar-item ">
Golang客户端
</a>
<a href="/zh/clients/python-client"
class="navbar-item ">
Python客户端
</a>
<a href="/zh/clients/node-client"
class="navbar-item is-active">
NodeJS客户端
</a>
<a href="/zh/clients/scala-client"
class="navbar-item ">
Scala客户端
</a>
</div>
</div>
<!--dropdown-->
<div class="navbar-item has-dropdown is-hoverable">
<a href=""
class="navbar-link ">
<span>
生态工具
</span>
</a>
<div class="navbar-dropdown">
<a href="/zh/docs/tools/shell"
class="navbar-item ">
Pegasus Shell 工具
</a>
<a href="https://github.com/pegasus-kv/admin-cli"
class="navbar-item ">
集群管理命令行
</a>
<a href="https://github.com/pegasus-kv/pegic"
class="navbar-item ">
数据访问命令行
</a>
</div>
</div>
<!--dropdown-->
<div class="navbar-item has-dropdown is-hoverable">
<a href=""
class="navbar-link ">
<span>
用户接口
</span>
</a>
<div class="navbar-dropdown">
<a href="/zh/api/ttl"
class="navbar-item ">
TTL
</a>
<a href="/zh/api/single-atomic"
class="navbar-item ">
单行原子操作
</a>
<a href="/zh/api/redis"
class="navbar-item ">
Redis适配
</a>
<a href="/zh/api/geo"
class="navbar-item ">
GEO支持
</a>
<a href="/zh/api/http"
class="navbar-item ">
HTTP接口
</a>
</div>
</div>
<!--dropdown-->
<div class="navbar-item has-dropdown is-hoverable">
<a href=""
class="navbar-link ">
<span>
高效运维
</span>
</a>
<div class="navbar-dropdown">
<a href="/zh/administration/deployment"
class="navbar-item ">
集群部署
</a>
<a href="/zh/administration/config"
class="navbar-item ">
配置说明
</a>
<a href="/zh/administration/rebalance"
class="navbar-item ">
负载均衡
</a>
<a href="/zh/administration/monitoring"
class="navbar-item ">
可视化监控
</a>
<a href="/zh/administration/rolling-update"
class="navbar-item ">
集群升级
</a>
<a href="/zh/administration/scale-in-out"
class="navbar-item ">
集群扩容缩容
</a>
<a href="/zh/administration/resource-management"
class="navbar-item ">
资源管理
</a>
<a href="/zh/administration/cold-backup"
class="navbar-item ">
冷备份
</a>
<a href="/zh/administration/meta-recovery"
class="navbar-item ">
元数据恢复
</a>
<a href="/zh/administration/replica-recovery"
class="navbar-item ">
Replica数据恢复
</a>
<a href="/zh/administration/zk-migration"
class="navbar-item ">
Zookeeper迁移
</a>
<a href="/zh/administration/table-migration"
class="navbar-item ">
Table迁移
</a>
<a href="/zh/administration/table-soft-delete"
class="navbar-item ">
Table软删除
</a>
<a href="/zh/administration/table-env"
class="navbar-item ">
Table环境变量
</a>
<a href="/zh/administration/remote-commands"
class="navbar-item ">
远程命令
</a>
<a href="/zh/administration/partition-split"
class="navbar-item ">
Partition-Split
</a>
<a href="/zh/administration/duplication"
class="navbar-item ">
跨机房同步
</a>
<a href="/zh/administration/compression"
class="navbar-item ">
数据压缩
</a>
<a href="/zh/administration/throttling"
class="navbar-item ">
流量控制
</a>
<a href="/zh/administration/experiences"
class="navbar-item ">
运维经验
</a>
<a href="/zh/administration/manual-compact"
class="navbar-item ">
Manual Compact功能
</a>
<a href="/zh/administration/usage-scenario"
class="navbar-item ">
Usage Scenario功能
</a>
<a href="/zh/administration/bad-disk"
class="navbar-item ">
坏盘检修
</a>
<a href="/zh/administration/whitelist"
class="navbar-item ">
白名单
</a>
<a href="/zh/administration/backup-request"
class="navbar-item ">
Backup Request
</a>
<a href="/zh/administration/hotspot-detection"
class="navbar-item ">
热点检测
</a>
</div>
</div>
</div>
</div>
</nav>
<nav class="navbar is-hidden-mobile">
<div class="navbar-start w-full">
<div class="navbar-item pl-0 w-full">
<!--TODO(wutao): Given the limitation of docsearch that couldn't handle multiple input,
I make searchbox only shown in desktop. Fix this issue when docsearch.js v3 released.
Related issue: https://github.com/algolia/docsearch/issues/230-->
<div id="docsearch"></div>
</div>
</div>
<div class="navbar-end">
<div class="navbar-item">
<!--A simple language switch button that only supports zh and en.-->
<!--IF its language is zh, then switches to en.-->
<!--If you don't want a url to be relativized, you can add a space explicitly into the href to
prevents a url from being relativized by polyglot.-->
<a class="button is-light is-outlined is-inverted" href=" /clients/node-client"><strong>En</strong></a>
</div>
</div>
</nav>
<section class="hero is-info lg:mr-3">
<div class="hero-body">
<p class="title is-size-2 is-centered">NodeJS客户端</p>
</div>
</section>
<section class="section" style="padding-top: 2rem;">
<div class="content">
<h1 id="安装nodejs客户端">安装NodeJs客户端</h1>
<p>项目地址:<a href="https://github.com/apache/incubator-pegasus/tree/master/nodejs-client">Pegasus NodeJS Client</a>
下载并将客户端依赖添加到package.json中:<br />
<code class="language-plaintext highlighter-rouge">npm install pegasus-nodejs-client --save</code></p>
<h1 id="创建关闭客户端">创建/关闭客户端</h1>
<h2 id="create">create</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>let pegasusClient = require('pegasus-nodejs-client');
/**
* Create a client instance
* @param {Object} configs
* {Array} configs.metaServers required
* {String} configs.metaServers[i] required
* {Number} configs.operationTimeout(ms) optional
* {Object} configs.log optional
* @return {Client} client instance
* @throws {InvalidParamException}
*/
client = pegasusClient.create({
metaServers: ['127.0.0.1:34601', '127.0.0.1:34602', '127.0.0.1:34603'],
operationTimeout : 5000,
log : log,
});
</code></pre></div></div>
<ul>
<li>metaServers为meta server地址列表,为必填项</li>
<li>operationTimeout为本次操作的超时时间,单位是毫秒,默认是1000ms</li>
<li>log为日志库实例</li>
<li>我们使用日志库 <a href="https://github.com/log4js-node/log4js-node">log4js</a></li>
<li>默认使用的日志配置在<code class="language-plaintext highlighter-rouge">log_config.js</code>文件中,配置如下:
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>let filename = "./logs/"+process.pid+"/pegasus-nodejs-client.log";
let logConfig = {
appenders: {
pegasus: {
type: "file",
filename: filename,
maxLogSize: 104857600,
backups: 10
}
},
categories: {
default: { appenders: ["pegasus"], level: "INFO" }
}
};
</code></pre></div> </div>
<p>上述配置表示,会将错误级别等于及高于INFO级别的日志存储在文件中,每个日志文件最大100M,最多保留10个日志文件</p>
</li>
<li>若不想使用默认配置,则需要重新定义如上的logConfig对象,作为创建客户端时的log对象</li>
<li>当参数有误时,会抛出异常,停止后续操作</li>
</ul>
<h2 id="close">close</h2>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>// close client when you do not need to use it
client.close();
</code></pre></div></div>
<h1 id="接口">接口</h1>
<h2 id="get">get</h2>
<p>读单行数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Get value
* @param {String} tableName
* @param {Object} args
* {Buffer} args.hashKey required
* {Buffer} args.sortKey required
* {Number} args.timeout(ms) optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.get(
tableName,
args,
function(err, result){
// if get operation succeed, err will be null,
// result.hashKey is hashKey, result.sortKey is sortKey, result.value is value
// else err will be instance of PException, result will be null
}
);
</code></pre></div></div>
<ul>
<li>get操作的必填参数有表名,hashKey,sortKey和callback</li>
<li>hashKey,sortKey和value都是Buffer对象,这与pegasus服务端key与value均为byte的语义保持一致</li>
<li>超时时间为可选参数,默认为创建客户端时设定的超时时间</li>
<li>当读操作成功时,callback的err为空,result.value为读到的值</li>
<li>当读操作失败时,callback的result为空</li>
<li>客户端不认为读不到值时错误,因此当读不到值时,err仍为空,result.value为<code class="language-plaintext highlighter-rouge">Buffer('')</code></li>
</ul>
<h2 id="set">set</h2>
<p>写单行数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Set Value
* @param {String} tableName
* @param {Object} args
* {Buffer} args.hashKey required
* {Buffer} args.sortKey required
* {Buffer} args.value required
* {Number} args.ttl(s) optional
* {Number} args.timeout(ms) optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.set(
tableName,
args,
function(err){
// if set operation succeed, err will be null
// else err will be instance of PException
}
);
</code></pre></div></div>
<ul>
<li>set操作的必填参数有表名,hashKey,sortKey,value和callback</li>
<li>ttl的含义为过期时间,单位为秒,默认ttl为0,则表示该数据不过期,若用户设置ttl为86400s,则表示该数据将在1天之后过期,用户在1天之后将无法读取到该数据</li>
</ul>
<h2 id="del">del</h2>
<p>删除单行数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Delete value
* @param {String} tableName
* @param {Object} args
* {Buffer} args.hashKey required
* {Buffer} args.sortKey required
* {Number} args.timeout(ms) optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.del(
tableName,
args,
function(err){
// if set operation succeed, err will be null
// else err will be instance of PException
}
);
</code></pre></div></div>
<ul>
<li>del操作的必填参数有表名,hashKey,sortKey和callback</li>
</ul>
<h2 id="multiget">multiGet</h2>
<p>读同一个hashKey下的多行数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Multi Get
* @param {String} tableName
* @param {Object} args
* {Buffer} args.hashKey required
* {Array} args.sortKeyArray required
* {Buffer} args.sortKeyArray[i] required
* {Number} args.timeout(ms) optional
* {Number} args.maxFetchCount optional
* {Number} args.maxFetchSize optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.multiGet(
tableName,
args,
function(err, result){
// if operation succeed, err will be null,
// result[i].hashKey is hashKey, result[i].sortKey is sortKey, result[i].value is value
// else err will be instance of PException, result will be null
}
);
</code></pre></div></div>
<ul>
<li>multiGet操作的必填参数为表名,hashKey,sortKey数组和callback</li>
<li>若sortKey数据为空数组,则表示期望获取该hashKey下的所有sortKey的值</li>
<li>maxFetchCount为最多获取数据的条数,默认为100</li>
<li>maxFetchSize为最大获取数据的大小,默认为1000000字节</li>
</ul>
<h2 id="batchget">batchGet</h2>
<p>读取一批数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Batch Get value
* @param {String} tableName
* @param {Array} argsArray
* {Buffer} argsArray[i].hashKey required
* {Buffer} argsArray[i].sortKey required
* {Number} argsArray[i].timeout(ms) optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.batchGet(
tableName,
argsArray,
function(err, result){
// err will be always be null, result is {'error': err, 'data': result} array
// if batchGet[i] operation succeed, result[i].error will be null
// result[i].data.hashKey is hashKey, result[i].data.sortKey is sortKey, result[i].data.value is value
// else result[i].error will be instance of PException, result[i].data will be null
}
);
</code></pre></div></div>
<ul>
<li>batchGet操作的必填参数为表名,hashKey数组,sortKey数组和callback</li>
<li>与multiGet不同的是,batchGet支持读多个hashKey的值</li>
<li>batchGet将等待所有本次batch的所有get操作都返回结果后才返回</li>
<li>callback的err总是为null</li>
<li>callback的result是一个数组,result[i].error表示第i个get操作的出错情况,result[i].data表示第i个get操作的结果</li>
</ul>
<h2 id="multiset">multiSet</h2>
<p>写同一个hashKey下的多行数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Multi Set
* @param {String} tableName
* @param {Object} args
* {Buffer} args.hashKey required
* {Array} args.sortKeyValueArray required
* {'key' : sortKey, 'value' : value}
* {Number} args.timeout(ms) optional
* {Number} args.ttl(s) optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.multiSet(
tableName,
args,
function(err){
// if set operation succeed, err will be null
// else err will be instance of PException
}
);
</code></pre></div></div>
<ul>
<li>multiSet操作的必填参数为表名,hashKey,sortKey-value对象数组和callback</li>
</ul>
<h2 id="batchset">batchSet</h2>
<p>写入一批数据</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/**
* Batch Set value
* @param {String} tableName
* @param {Array} argsArray
* {Buffer} argsArray[i].hashKey required
* {Buffer} argsArray[i].sortKey required
* {Buffer} argsArray[i].value required
* {Number} argsArray[i].ttl optional
* {Number} argsArray[i].timeout(ms) optional
* @param {Function} callback
* @throws{InvalidParamException} callback is not function
*/
client.batchSet(
tableName,
argsArray,
function(err, result){
// err will be always be null, result is {'error': err} array
// if batchSet[i] operation succeed, result[i].error will be null
// else result[i].error will be instance of PException
}
);
</code></pre></div></div>
<ul>
<li>batchSet操作的必填参数为表名,hashKey-sortKey-value对象数组和callback</li>
<li>callback的err总是为null,result[i].error表示第i个set操作的出错情况</li>
</ul>
</div>
</section>
<footer class="footer">
<div class="container">
<div class="content is-small has-text-centered">
<div style="margin-bottom: 20px;">
<a href="http://incubator.apache.org">
<img src="/assets/images/egg-logo.png"
width="15%"
alt="Apache Incubator"/>
</a>
</div>
Copyright &copy; 2023 <a href="http://www.apache.org">The Apache Software Foundation</a>.
Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version
2.0</a>.
<br><br>
Apache Pegasus is an effort undergoing incubation at The Apache Software Foundation (ASF),
sponsored by the Apache Incubator. Incubation is required of all newly accepted projects
until a further review indicates that the infrastructure, communications, and decision making process
have stabilized in a manner consistent with other successful ASF projects. While incubation status is
not necessarily a reflection of the completeness or stability of the code, it does indicate that the
project has yet to be fully endorsed by the ASF.
<br><br>
Apache Pegasus, Pegasus, Apache, the Apache feather logo, and the Apache Pegasus project logo are either
registered trademarks or trademarks of The Apache Software Foundation in the United States and other
countries.
</div>
</div>
</footer>
</div>
<!-- right panel -->
<div class="dashboard-panel is-small is-scrollable is-hidden-mobile">
<p class="menu-label">
<span class="icon">
<i class="fa fa-bars" aria-hidden="true"></i>
</span>
本页导航
</p>
<ul class="menu-list">
<li><a href="#安装nodejs客户端">安装NodeJs客户端</a></li>
<li><a href="#创建关闭客户端">创建/关闭客户端</a>
<ul>
<li><a href="#create">create</a></li>
<li><a href="#close">close</a></li>
</ul>
</li>
<li><a href="#接口">接口</a>
<ul>
<li><a href="#get">get</a></li>
<li><a href="#set">set</a></li>
<li><a href="#del">del</a></li>
<li><a href="#multiget">multiGet</a></li>
<li><a href="#batchget">batchGet</a></li>
<li><a href="#multiset">multiSet</a></li>
<li><a href="#batchset">batchSet</a></li>
</ul>
</li>
</ul>
</div>
</div>
<script src="/assets/js/app.js" type="text/javascript"></script>
<script>
docsearch({
container: '#docsearch',
appId: 'QRN30RBW0S',
indexName: 'pegasus-apache',
apiKey: 'd3a3252fa344359766707a106c4ed88f',
debug: true
});
</script>
</body>
</html>