yum install -y java即可。接口名 | 接口用途 |
addRecord | 增加一条 TcaplusDB 记录,记录必须包含所有主键字段值 |
getRecord | 查询一条 TcaplusDB 记录,必须指定主键字段查询 |
setRecord | 更新一条 TcaplusDB 记录,必须指定主键字段更新,若记录不存在则插入一条新记录 |
deleteRecord | 删除一条 TcaplusDB 记录,必须指定主键字段删除 |
fieldSetRecord | 更新指定字段,必须指定主键字段更新 |
fieldGetRecord | 获取指定字段,必须指定主键字段获取 |
fieldIncRecord | 更新指定字段,只针对数值类型字段,自增或自减场景,必须指定主键字段更新 |
partkeyGetRecord | 根据指定的索引名和对应的索引字段值获取相应 TcaplusDB 记录(一条或多条),必须指定对应的索引字段值 |
tcaplusdb-restapi-java-sdk-1.0-assembly.zip 到 CVM 目录,请参见 如何将本地文件拷贝到云服务器,解压后目录名tcaplusdb-restapi-java-sdk-1.0。tcaplusdb-restapi-java-sdk-1.0/conf/config.properties。配置内容如下:#replace with your table endpointendpoint=http://10.xx.xx.16#replace with your table access idaccess_id=60#replace with your table access passwordaccess_password=Tcaxxx19#replace with your table group idtable_group_id=1#replace with your table nametable_name=game_players#optional, configure the returning fields for GetRecord API, multiple fields with comma delimeterget_select_fields=#required, configure the returing fields for FieldGetRecord APIfield_get_select_fields=game_server_id,is_online#optional, configure the returning fields for PartkeyGetRecord APIpart_key_get_select_fields=game_server_id,is_online#required, configure the updating fields for FieldSetRecord APIfield_set_fields=game_server_id,pay.amount#required, configure the index keys for PartkeyGetRecord APIpart_key_index_keys=player_id,player_name#required, configure the index name for PartkeyGetRecord APIpart_key_index_name=index_1#optional, configure the limit number of records per request to return for PartkeyGetRecord API, value range: >0part_key_limit = 10#optional, configure the offset position to return for PartkeyGetRecord API, value range: >=0part_key_offset = 0
tcaplusdb-restapi-java-sdk-1.0/conf目录。文件名 | 文件说明 |
add_data.json | 用于 addRecord 示例接口,增加一条记录 |
set_data.json | 用于 updateRecord 示例接口,更新一条记录字段值 |
delete_data.json | 用于 deleteRecord 示例接口,删除记录的主键值 |
get_data.json | 用于 getRecord 示例接口,获取记录的主键值 |
field_get_data.json | 用于 fieldGetRecord 示例接口,获取部分字段的值 |
field_set_data.json | 用于 fieldSetRecord 示例接口,更新部分字段的值 |
field_inc_data.json | 用于 fieldIncRecord 示例接口,增加部分字段的值,针对数值类型字段 |
partkey_get_data.json | 用于 partkeyGetRecord 示例接口,根据索引获取记录值 |
tcaplusdb-restapi-java-sdk-1.0/bin/run.sh,执行方法如下:#增加一条记录sh bin/run.sh add#获取一条记录sh bin/run.sh get#更新一条记录sh bin/run.sh set#删除一条记录sh bin/run.sh delete#更新部分字段sh bin/run.sh field_set#获取部分字段sh bin/run.sh field_get#更新部分字段值(数据类型)sh bin/run.sh field_inc#根据索引获取一条记录sh bin/run.sh partkey_get
{"player_id":1,"player_name":"test","player_email":"test@email.com", "game_server_id":2,"login_timestamp":[],"logout_timestamp":[],"is_online":true,"pay":{"pay_id":1,"amount":20,"method":3}}
{"player_id":1,"player_name":"test","player_email":"test@email.com"}
config.properties中定义了get_select_fields配置项,用于指定要返回的字段名,如果配置为空则默认返回记录所有字段,如果不为空则返回指定的字段值。{"player_id":1,"player_name":"test","player_email":"test@email.com", "game_server_id":2,"login_timestamp":[],"logout_timestamp":[],"is_online":false,"pay":{"pay_id":1,"amount":30,"method":3}}
{"player_id":1,"player_name":"test","player_email":"test@email.com"}
{"player_id":1,"player_name":"test","player_email":"test@email.com", "game_server_id":3,"is_online":false, "login_timestamp":[],"logout_timestamp":[],"pay":{"pay_id":1,"amount":40,"method":3}}
config.properties中定义了field_set_fields配置项,指定对应的字段名即可,用逗号隔开,不能为空。{"player_id":1,"player_name":"test","player_email":"test@email.com"}
config.properties中定义了field_get_select_fields配置项, 指定需要返回的字段值,不能为空。{"player_id":1,"player_name":"test","player_email":"test@email.com", "pay":{"amount":50}}
{"player_id":1,"player_name":"test","player_email":"test@email.com"}
config.properties中定义:part_key_index_name表示索引名,part_key_index_keys表示索引字段名,这两个配置项不能为空。part_key_get_select_fields来指定要返回的字段,可以为空。256KB,limit 的设置依赖于单条记录大小。推荐设置策略:TotalNum 和 RemainNum标识来判断数据是否获取完全。#step1,准备批量演示数据,参考 conf/batch_add_data.json. 设置 limit 和 offset 值part_key_limit = 2part_key_offset = 0#step2,批量增加演示数据,用 batch_add 命令,增加3条记录sh bin/run.sh batch_add#step3,调用 partkey_get 命令,会执行 partkeyGetRecord 两次:一次不带 limit 和 offset , 一次带 limit 和 offset,观察两次执行的结果差异。sh bin/run.sh partkey_get#step4,不带 limit 和 offset 的响应数据如下,总共4条数据{"MultiRecords":[{"RecordVersion":3,"Record":{"game_server_id":3,"is_online":true,"player_email":"test@email.com","player_id":1,"player_name":"test"}},{"RecordVersion":1,"Record":{"game_server_id":3,"is_online":true,"player_email":"test1@email.com","player_id":1,"player_name":"test"}},{"RecordVersion":1,"Record":{"game_server_id":4,"is_online":true,"player_email":"test2@email.com","player_id":1,"player_name":"test"}},{"RecordVersion":1,"Record":{"game_server_id":5,"is_online":true,"player_email":"test3@email.com","player_id":1,"player_name":"test"}}],"TotalNum":4,"RemainNum":0,"ErrorCode":0,"ErrorMsg":"Succeed"}#step5,带 limit 和 offset 的响应数据如下,只返回2条和 limit 配置值一致{"MultiRecords":[{"RecordVersion":3,"Record":{"game_server_id":3,"is_online":true,"player_email":"test@email.com","player_id":1,"player_name":"test"}},{"RecordVersion":1,"Record":{"game_server_id":3,"is_online":true,"player_email":"test1@email.com","player_id":1,"player_name":"test"}}],"TotalNum":4,"RemainNum":2,"ErrorCode":0,"ErrorMsg":"Succeed"}
文档反馈