game_players.proto
. For more information, please see Creating Table.yum install -y java
.API Name | Description |
addRecord | Adds TcaplusDB record, which must contain the values of all primary key fields |
getRecord | Queries TcaplusDB record. A primary key field must be specified |
setRecord | Updates TcaplusDB record. A primary key field must be specified for the update. If the record does not exist, a new one will be inserted |
deleteRecord | Deletes TcaplusDB record. A primary key field must be specified |
fieldSetRecord | Updates specified field. A primary key field must be specified |
fieldGetRecord | Gets specified field. A primary key field must be specified |
fieldIncRecord | Updates specified field, which can be used only to auto-increment/decrement numeric fields. A primary key field must be specified |
partkeyGetRecord | Gets one or more TcaplusDB records based on specified index name and corresponding index field value. The corresponding index field value must be specified |
tcaplusdb-restapi-java-sdk-1.0-assembly.zip
to the CVM instance directory. For more information, please see Copying Local File to CVM. After decompression, the directory name will be tcaplusdb-restapi-java-sdk-1.0
.tcaplusdb-restapi-java-sdk-1.0/conf/config.properties
, and its content is as follows:#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
directory as JSON files.Filename | File Description |
add_data.json | Data for addRecord API, which is used to add a record |
set_data.json | Data for updateRecord API, which is used to update a record value |
delete_data.json | Data for deleteRecord API, which is used to delete the primary key value of a record |
get_data.json | Data for getRecord API, which is used to get the primary key value of a record |
field_get_data.json | Data for fieldGetRecord API, which is used to get the values of specified fields |
field_set_data.json | Data for fieldSetRecord API, which is used to update the values of specified fields |
field_inc_data.json | Data for fieldIncRecord API, which is used to increase the values of specified numeric fields |
partkey_get_data.json | Data for partkeyGetRecord API, which is used to get a record value based on the index |
tcaplusdb-restapi-java-sdk-1.0/bin/run.sh
and can be run as follows:# Add a recordsh bin/run.sh add# Get a recordsh bin/run.sh get# Update a recordsh bin/run.sh set# Delete a recordsh bin/run.sh delete# Update specified fieldssh bin/run.sh field_set# Get specified fieldssh bin/run.sh field_get# Update the values of specified fields (in numeric type)sh bin/run.sh field_inc# Get a record based on the indexsh 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"}
get_select_fields
configuration item defined in the config.properties
configuration file is used to specify the names of the fields to be returned. If it is left empty, all fields of the record will be returned by default; otherwise, the values of the specified fields will be returned.{"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}}
field_set_fields
configuration item defined in the config.properties
configuration file. Multiple fields should be separated with commas, and the value cannot be empty.{"player_id":1,"player_name":"test","player_email":"test@email.com"}
field_get_select_fields
configuration item defined in the config.properties
configuration file, and the value cannot be empty.fieldSetRecord
API, it can update field values only in numeric type, such as increasing or decreasing a value. The entered data must contain a primary key field and the numeric fields to be updated. The data is in JSON format as shown below:{"player_id":1,"player_name":"test","player_email":"test@email.com", "pay":{"amount":50}}
pay.amount
is 100, and the value of the input parameter in the request is 50, then the final value will be 150.{"player_id":1,"player_name":"test","player_email":"test@email.com"}
part_key_index_name
and part_key_index_keys
configuration items defined in the config.properties
configuration file, respectively. The two configuration items cannot be empty.part_key_get_select_fields
in the configuration file; otherwise, leave it empty.256 KB
, and the limit
value is subject to the size of one single record. We recommend you set it as follows:limit
to 256 KB / record size; for example, if the record size is 10 KB, we recommend you set limit
to a value between 20 and 25.limit
to 1, i.e., only one record will be returned by one request.limit
and offset
are set, to get the full data based on the index key, you need to judge whether the obtained data is complete based on the TotalNum
and RemainNum
flags returned in the response packet.limit
and offset
in the following steps:# Step 1. Prepare batch demo data and set the values of `limit` and `offset` as instructed in `conf/batch_add_data.json`.part_key_limit = 2part_key_offset = 0# Step 2. Add demo data in batches. Run the `batch_add` command to add three records.sh bin/run.sh batch_add# Step 3. Call the `partkey_get` command, and `partkeyGetRecord` will be executed twice: in the first execution, `limit` and `offset` are not set; in the second execution, `limit` and `offset` are set. Check the differences between the two execution results.sh bin/run.sh partkey_get# Step 4. The response data with `limit` and `offset` not set is as follows, which contains four data entries in total:{"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"}# Step 5. The response data with `limit` and `offset` set is as follows, which contains only two data entries subject to the `limit` value:{"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"}