当前位置:网站首页>【深入理解TcaplusDB技术】示例代码——异步调用接口
【深入理解TcaplusDB技术】示例代码——异步调用接口
2022-04-22 12:11:00 【InfoQ】
【深入理解TcaplusDB技术】示例代码——异步调用接口
本文说明
准备工作
示例代码
import com.tencent.tcaplus.client.Client;
import com.tencent.tcaplus.client.ClientFactory;
import com.tencent.tcaplus.client.Record;
import com.tencent.tcaplus.client.Request;
import com.tencent.tcaplus.client.Response;
import com.tencent.tdr.tcaplus_protocol_cs.TcaplusProtocolCsConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public class Example {
public static void main(String[] arguments) throws InterruptedException {
// 1. 准备环境信息
// 1.1. 目录服务地址列表
List<String> dirList = new ArrayList<String>();
dirList.add("tcp://x.x.x.x:9999");
dirList.add("tcp://y.y.y.y:9999");
// 1.2. 业务ID
int appId = 1;
// 1.3. 业务密码
String appPassword = "****************";
// 1.4. 表格组ID
int tableGroupId = 1;
// 1.5. 表格名称
String tableName = "test";
// 2. 创建客户端
Client client = ClientFactory.createClient(appId, tableGroupId, appPassword, dirList);
try {
// 3. 构造查询数据的请求
// 3.1. 获取请求对象。为了提升SDK性能,Request对象是复用的
Request request = client.acquireRequest();
// 3.2. 设置请求类型和目标表名
request.setCmd(TcaplusProtocolCsConstants.TCAPLUS_CMD_GET_REQ);
request.setTableName(tableName);
// 3.3. 设置各个Key字段的值
Record record = request.addRecord();
record.setKeyInt("gameid", 1);
record.setKeyInt("itemid", 1);
record.setKeyString("name", "test");
// 3.4. 添加需要查询的Value字段
request.addFieldName("typeid");
request.addFieldName("Data");
request.addFieldName("uname");
CountDownLatch latch = new CountDownLatch(1);
// 4. 异步发送请求,并指定返回结果处理器,post方法会立即返回
client.post(request, new Future() {
@Override
public void onResponse(Response response) {
// 5. 处理结果
if (response.getResult() == 0) {
// 查询数据成功
Record result = response.fetchRecord();
// TODO 可在此处添加数据查询成功的后续处理代码
} else {
// 查询数据失败
// TODO 可在此处添加数据查询失败的后续处理代码
}
}
});
latch.await();
} finally {
// 6. 销毁客户端对象
ClientFactory.destroyClient(client);
}
}
}

- TcaplusDB是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://xie.infoq.cn/article/f8b545dddaf9e9a37b0e89261
边栏推荐
- Order details page
- Distributed transaction and lock
- 案例4-1.4:堆中的路径 (小顶堆的模拟建立和模拟路径)
- 模糊集合论
- 哇哦,好丰富呀。
- The fourth play of MySQL learning - detailed explanation of multi table query classification and case exercise source code
- 深入解析View的绘制源码流程
- 案例4-1.7:文件传输(并查集)
- Father of MySQL: the code should be written at once, not later
- 一种自动切换过流保护模块的热泵装置保护电路介绍(ACS758/CH704应用案例)
猜你喜欢

MySQL学习第四弹——多表查询分类以及案例练习源码详解

A note that allows you to capture the offer of a large factory. Come and get it quickly

Developer friendly public chain Neo | how to connect web2 developers to Web3 world

软件智能:aaas系统的 AI服务功能:大纲图的无意识代理功能和八卦图的关系

What happens when you run the NPM install command?

如何写出有价值的竞品分析报告?

Heap overflow of kernel PWN basic tutorial

The second day of playing 51 single chip microcomputer in 14 days -- thought we were playing LED lights? No, no, no, we're playing with the bottom I / O^-^

电工第二讲

开发者友好型公链Neo | 如何连接 Web2 开发者到 Web3 世界
随机推荐
封装的方法
Electrician Lecture 1
NLP数据集整理(更新中)
案例4-1.7:文件传输(并查集)
Circuit experiment -- Experiment 4 Davinan theorem and Norton theorem
“开源之夏”活动火热报名中,丰厚奖金等你来拿!
费用详情页面
Eight misunderstandings in writing
How do I test the shuttle application? Unit test
什么样的SQL报表可以使用max–pt函数?
自动化测试的生命周期是什么?
LeetCode383. 赎金信
Ptorch quantification (torch. Quantification)
LeetCode454. Four number addition II
Software intelligence: the AI service function of AAAS system: the relationship between the unconscious agent function of outline map and gossip map
【深入理解TcaplusDB技术】读取列表指定位置数据接口说明——[List表]
Packaging method 2
实操教程|Pytorch - 弹性训练极简实现( 附源码)
CVPR2022 | 移动端手部三维重建
14天玩转51单片机第二天——以为咱们在玩LED灯?不不不,咱们在玩底层的输入输出^-^