当前位置:网站首页>【深入理解TcaplusDB技术】读取列表指定位置数据示例代码——[List表]
【深入理解TcaplusDB技术】读取列表指定位置数据示例代码——[List表]
2022-04-22 15:01:00 【数据库大师】
本文准备工作
参见章节: 准备工作。
示例代码
示例代码
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;
public class Example {
public static void main(String[] arguments) {
// 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. 设置请求类型和目标表名。注意:目标表必须是List表
request.setCmd(TcaplusProtocolCsConstants.TCAPLUS_CMD_LIST_GET_REQ);
request.setTableName(tableName);
// 3.3. 由于List表中,可以多个Key相同的数据,因此调用些接口时,
// 需要指定取数据列表中的第几个数据,本例中的0,表示取第1个,以此类推
Record record = request.addRecord(0);
// 3.4. 设置列表各个Key字段的值
record.setKeyInt("gameid", 1);
record.setKeyInt("itemid", 1);
record.setKeyString("name", "test");
// 3.5. 添加需要查询的Value字段
request.addFieldName("typeid");
request.addFieldName("Data");
request.addFieldName("uname");
// 4. 发送请求,并获取结果
Response response = client.poll(request);
// 5. 处理结果
if (response.getResult() == 0) {
// 读取数据成功
Record result = response.fetchRecord();
// TODO 可在此处添加数据读取成功的后续处理代码
} else {
// 读取数据失败
// TODO 可在此处添加数据读取失败的后续处理代码
}
} finally {
// 6. 销毁客户端对象
ClientFactory.destroyClient(client);
}
}
}

TcaplusDB是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。
版权声明
本文为[数据库大师]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Tcapshuju/article/details/124339029
边栏推荐
- Bootsrap 模态框文字超出处理
- View your own system activation type
- 关于阿里云OSS资源STS访问控制
- leetcode面试题 17.16. 按摩师(简单)
- Llvm founder Chris LATTNER reviews and looks forward to the compiler
- Configure MySQL Cluster with MYCAT (2) -- configure MySQL master-slave replication
- Machine learning model fusion method!
- 【ORB_SLAM2源码解读】分析ORB_SLAM2 RGBD 第1帧是怎么计算位置姿态的
- 记录一个sql,查询用户最后任职的一家公司,并根据企业名称+用户名称进行搜索
- 运输层——无连接运输:UDP(2)
猜你喜欢
随机推荐
2022 chemical automation control instrument examination question bank and online simulation examination
思科模拟器EVE-NG如何导入镜像
Take you to understand the principle of highly flexible spark architecture
带你了解极具弹性的Spark架构的原理
Learning records 568@RSA Public key system and its decryption proof mode II
干货!对有目标对抗图像迁移性的反思
Alibaba cloud IOT transfer to PostgreSQL database scheme
Watch out for spies! Safeguard national security, you and I guard together
Memcpy() function copies two-dimensional array & memcmp() function compares two-dimensional array
学习记录568@RSA公钥体系及其解密证明方式二
memcpy( )函数复制二维数组 & memcmp( )函数比较二维数组
中一科技深交所IPO:市值83亿 湖北诞生又一家上市企业
JVM的垃圾回收Serial、Serial Old、Parallel Scavenge、Parallel Old的介绍和STW(Stop The World)
阿里云IoT流转到postgresql数据库方案
Love station network keyword mining query tool - batch website keyword mining export software free download
leetcode746. 使用最小花费爬楼梯(简单)
Go语言简介,环境安装,基本结构
Redis面试题汇总,mysql索引优化面试题常问
儿子18岁上大学的时候我们已经60了,给他准备一笔钱买什么理财产品最靠谱?
When our son was 18 years old and went to college, we were already 60. What financial products are the most reliable for him to buy?




![[Mysql] CHAR_LENGTH函数](/img/1c/57bc70f35429d0add2dbee99e06c1c.png)
![[elt.zip] openharmony's paper growth plan -- multidimensional exploration and universal lossless compression](/img/76/73c92acd32a51aa6e054da44205e23.png)



