当前位置:网站首页>[in depth understanding of tcallusdb technology] sample code for reading data according to some key field values - [generic table]
[in depth understanding of tcallusdb technology] sample code for reading data according to some key field values - [generic table]
2022-04-22 15:14:00 【Database master】
Preparation of this paper
See Chapter : preparation .
Sample code
Be careful : By part Key Before the field value reads the data , First create a key with the corresponding key value as Key The index of , Otherwise, an error will be reported that the index cannot be found . Reference resources Define index .
Sample code
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. Prepare environmental information
// 1.1. Directory service address list
List<String> dirList = new ArrayList<String>();
dirList.add("tcp://x.x.x.x:9999");
dirList.add("tcp://y.y.y.y:9999");
// 1.2. Business ID
int appId = 1;
// 1.3. Business password
String appPassword = "****************";
// 1.4. Table group ID
int tableGroupId = 1;
// 1.5. Table name
String tableName = "test";
// 2. Create client
Client client = ClientFactory.createClient(appId, tableGroupId, appPassword, dirList);
try {
// 3. The structure is based on part Key A request to read data from a field value
// 3.1. Get request object . In order to improve SDK performance ,Request Objects are reusable
Request request = client.acquireRequest();
// 3.2. Set request type and target table name
request.setCmd(TcaplusProtocolCsConstants.TCAPLUS_CMD_GET_BY_PRRTKEY_RES);
request.setTableName(tableName);
// 3.3. Settings section Key Value of field . Complete in this example Key from 3 Fields make up , But only one of the fields is specified when querying
Record record = request.addRecord();
record.setKeyInt("gameid", 1);
// 3.4. Add the data to be read Value Field
request.addFieldName("typeid");
request.addFieldName("Data");
request.addFieldName("uname");
// 3.5. Set to return only results from the list offset At the beginning number Data , If it is not set, all qualified data will be returned
int offset = 0;
int number = 100;
request.setPartkeyGetParam(offset, number);
// 4. Send a request , And get the results
Response response = client.poll(request);
// 5. Processing results
if (response.getResult() == 0) {
// Read data successfully
Record result;
while ((result = response.fetchRecord()) != null) {
// TODO The subsequent processing code of successful data reading can be added here
}
} else {
// Failed to read data
// TODO The subsequent processing code of data reading failure can be added here
}
} finally {
// 6. Destroy client objects
ClientFactory.destroyClient(client);
}
}
}

TcaplusDB It's a distributed product of Tencent NoSQL database , The code for storage and scheduling is completely self-developed . With cache + Landing fusion architecture 、PB Levels of storage 、 Millisecond delay 、 Lossless horizontal expansion and complex data structure . At the same time, it has rich ecological environment 、 Easy migration 、 Extremely low operation and maintenance costs and five nine high availability features . Customer coverage game 、 Internet 、 government affairs 、 Finance 、 Manufacturing and the Internet of things .
版权声明
本文为[Database master]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221501394898.html
边栏推荐
- 2022 chemical automation control instrument examination question bank and online simulation examination
- 人脸识别 (5) 基于MCTNN人脸检测(Pytorch)
- mysql初始化报错
- 数学史有没有必要读?关于数学教育,我们忽视了太多
- 2022 welder (primary) operation certificate examination question bank and answers
- ROS通信机制二---服务通信
- 情报研判分析平台建设,情指勤一体化管理系统开发
- Watch out for spies! Safeguard national security, you and I guard together
- 基于 Traefik 的激进 TLS 安全配置实践
- Analysis on the characteristics of the official game economic model launched by platoffarm
猜你喜欢

【网络】传输层-UDP协议

【深入理解TcaplusDB技术】示例代码——数据分批返回

How to select current clamp or current probe

Introduction to JVM garbage collection serial, serial old, parallel scavenge, parallel old and STW (stop the world)

Overview of microservice Technology

About STS access control of Alibaba cloud OSS resources

【朋友圈服务器架构设计】

Redis的线程模型

Development trend of C in 2022

如何通过云效Projex项目协同提高团队更高效的协作能力
随机推荐
Record an SQL, query the company where the user last worked, and search according to the enterprise name + user name
思科模拟器EVE-NG如何导入镜像
Workplace PUA, five sins of managers
Redis小知识点汇总(无聊的时候瞄一眼)
2022危险化学品经营单位主要负责人考试题模拟考试题库模拟考试平台操作
琢磨琢磨方法引用以及lambda--白话Lambda和方法引用
About STS access control of Alibaba cloud OSS resources
wxWidgets学习笔记(一):解读Code::Blocks模板工程源代码
JVM的垃圾回收ParNew和CMS的介绍
Ansible 实用技巧 - 批量巡检站点 URL 状态
Web automation testing framework realizes the operation of web elements through JS
Tcallusdb Jun · industry news compilation (V)
【深入理解TcaplusDB技术】示例代码——数据分批返回
Installation and use of distributed task scheduling platform xxl-job
How to measure small current with oscilloscope and current probe
[Mysql] CHAR_ Length function
The GNU build system experience tutorial: Hello world example with Autoconf and automake
TcaplusDB君 · 行业新闻汇编(四)
数据库操作
合并两个有序链表——LeetCode