篇首语:本文由编程笔记#小编为大家整理,主要介绍了Tcaplus使用总结相关的知识,希望对你有一定的参考价值。
游戏数据库 TcaplusDB 是专为游戏设计的 NoSQL 分布式数据存储服务,支持 Protobuf 接口访问,Tcaplus 将 Cache 与硬盘结合,追求高性能的同时,也节省成本,很好地支持全区全服和分区分服,并针对游戏爆发增长和长尾运维特点提供不停机扩缩容、备份容灾、快速回档等全套解决方案,安全可信赖。目前应用于《王者荣耀》、《穿越火线》、《火影忍者》等数百款流行游戏。
特别要注意的是,在购买时,连接协议里选择TDR,这样就支持xml表定义了。
<metalib name&#61;"demo_table" tagsetversion&#61;"1" version&#61;"1">
<struct name&#61;"user" version&#61;"1" primarykey&#61;"user_id,server_id" splittablekey&#61;"user_id">
<entry name&#61;"user_id" type&#61;"string" size&#61;"450" desc&#61;"用户ID"/>
<entry name&#61;"server_id" type&#61;"uint64" desc&#61;"服务器ID" />
<entry name&#61;"nick_name" type&#61;"string" size&#61;"50" desc&#61;"昵称"/>
<entry name&#61;"desc" type&#61;"string" size&#61;"1024" desc&#61;"描述信息"/>
<entry name&#61;"state" type&#61;"Tinyuint" defaultvalue&#61;"0" desc&#61;"用户状态 0 : AVALIABLE, 1 DELETED"/>
<index name&#61;"index1" column&#61;"user_id"/>
<index name&#61;"index2" column&#61;"user_id,server_id"/>
struct>
<struct name&#61;"mail" version&#61;"1" primarykey&#61;"user_id,server_id,mail_id" splittablekey&#61;"user_id" >
<entry name&#61;"user_id" type&#61;"string" size&#61;"50" desc&#61;"用户ID"/>
<entry name&#61;"server_id" type&#61;"uint64" desc&#61;"服务器ID" />
<entry name&#61;"mail_id" type&#61;"uint64" desc&#61;"邮件ID" />
<entry name&#61;"state" type&#61;"Tinyuint" defaultvalue&#61;"0" desc&#61;"邮件状态(0 未读/1 已读)"/>
<entry name&#61;"from" type&#61;"string" size&#61;"50" desc&#61;"邮件发送方名字"/>
<entry name&#61;"subject" type&#61;"string" size&#61;"100" desc&#61;"邮件标题"/>
<entry name&#61;"content" type&#61;"string" size&#61;"1024" desc&#61;"邮件正文"/>
<index name&#61;"index1" column&#61;"user_id"/>
<index name&#61;"index2" column&#61;"user_id,server_id"/>
<index name&#61;"index3" column&#61;"user_id,mail_id"/>
struct>
<struct name&#61;"server" version&#61;"1" primarykey&#61;"server_id" splittablekey&#61;"server_id" >
<entry name&#61;"server_id" type&#61;"uint64" desc&#61;"服务器ID" />
<entry name&#61;"server_name" type&#61;"string" size&#61;"50" desc&#61;"服务器名称"/>
<entry name&#61;"capacity" type&#61;"uint64" desc&#61;"服务器最大承载容量"/>
<entry name&#61;"desc" type&#61;"string" size&#61;"1024" desc&#61;"描述信息"/>
<entry name&#61;"state" type&#61;"Tinyuint" defaultvalue&#61;"0" desc&#61;"server状态 0 : AVALIABLE, 1 DELETED"/>
<index name&#61;"index1" column&#61;"server_id"/>
struct>
metalib>
通过 client 工具访问 TcaplusDB 数据
1.tcaplus_client 是一个 TcaplusDB 表访问的客户端工具&#xff0c;可通过下表中的下载链接进行下载&#xff0c;Linux x86_64 平台的 TcaplusServiceAPI 发布包包含64位 Linux 版本的 tcaplus_client 工具&#xff1a;
版本 | 发布时间 | 操作系统 | 下载包名 |
---|---|---|---|
3.46.0.199033 | 2020/12/28 | Linux x86_64 | 下载 |
2.下载完成 TcaplusServiceApi 安装包后&#xff0c;将其 通过上传工具 上传至与 TcaplusDB 集群同一VPC&#xff0c;同一子网的云服务器中&#xff0c;然后解压。
tar -xf TcaplusPbApi3.46.0.199033.x86_64_release_20201210.tar.gz -C tcaplus
解压完成后&#xff0c;进入至 tcaplus 的 bin 目录中&#xff0c;并赋予可执行权限&#xff1a;
cd tcaplus/release/x86_64/bin
chmod &#43;x tcaplus_client
直接执行./tcaplus_client命令&#xff0c;会提示连接数据库所需的参数信息&#xff0c;用户可以根据自己的集群信息进行填写
参数 | 说明 | 是否必填 |
---|---|---|
-a | 接入 ID | 是 |
-z | 表格组 ID | 是 |
-s | 集群密码 | 是 |
-d | 集群 IP 地址及端口 | 是 |
-e | 需要执行的 SQL 语句&#xff0c;需要双引号包含 | 否 |
./tcaplus_client -a 15 -z 1 -s "ooxx" -d 172.16.0.7:9999
返回结果
&#61;&#61;&#61;&#61;&#61;&#61; Welcome to use tcaplus_client, use "help" to show usage &#61;&#61;&#61;&#61;&#61;&#61;
tcaplus> help;
--------------------------------------------------------------------------------
help: show usage of commands, example: "help select;".
show: get server status related information. executing "help show;" for details.
exit/quit: exit the client.
count: print record number in the database.
desc: print table field name and type.
select: query records from database.
insert: insert a new record into database.
replace: replace a record into the database.
update: update a record in the database.
delete: delete record(s) from database.
dump: dump records from database.
load: load records into the database.
--------------------------------------------------------------------------------
查看数据库集群状态
tcaplus> show status;
------------------------------------------------------------------
Access_id(app_id) &#61; 15
------------------------------------------------------------------
TableGroup_id(zone_id) &#61; 1
------------------------------------------------------------------
[dir_server_url]
dir_server_url[0]: 172.16.0.7:9999
------------------------------------------------------------------
[Proxys]
proxy[0]:tcp://172.16.0.7:10001 CONNECTED Authened
proxy[1]:tcp://172.16.0.7:10002 CONNECTED Authened
------------------------------------------------------------------
[The connected dir server]
tcp://172.16.0.7:9999
------------------------------------------------------------------
查看所有表
tcaplus> show tables;
----------------------------------------------------------
| Table Name Type Protocol |
----------------------------------------------------------
| server GENERIC TDR |
| user GENERIC TDR |
| mail GENERIC TDR |
----------------------------------------------------------
查看表结构
tcaplus> desc mail;
Table Structure From: Tcaplus System
TableName: mail
TableType: GENERIC, IdlType: TDRXML
SvrTdrCurrentVersion: 1
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|Field |Type |Key |Index|Size|Version|DefaultValue|Count|Select|Desc |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|user_id |string|PRI,SPLT|- |50 |1 |- |1 |- |用户ID |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|server_id|uint64|PRI |- |8 |1 |- |1 |- |服务器ID |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|mail_id |uint64|PRI |- |8 |1 |- |1 |- |邮件ID |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|state |uint8 |- |- |1 |1 |0 |1 |- |邮件状态(0 未读/1 已读)|
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|from |string|- |- |50 |1 |- |1 |- |邮件发送方名字 |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|subject |string|- |- |100 |1 |- |1 |- |邮件标题 |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
|content |string|- |- |1024|1 |- |1 |- |邮件正文 |
&#43;---------&#43;------&#43;--------&#43;-----&#43;----&#43;-------&#43;------------&#43;-----&#43;------&#43;-----------------------&#43;
7 rows in set (113 us)
插入&#xff1a;
tcaplus> insert into mail (user_id, server_id, mail_id, state,from,subject,content) values ("10001",1,202106301221,0,"系统","新手邮件","欢迎你&#xff0c;来到我们的虚拟世界");
insert success
insert time: 6427 us
查询表格的记录总数
tcaplus> count mail;
--------------------------------------------------------------------------------
| TableName Count |
--------------------------------------------------------------------------------
| mail 1 |
--------------------------------------------------------------------------------
查询&#xff1a;
tcaplus> select * from mail where user_id &#61; "10001" and server_id &#61; 1;
&#43;-------&#43;---------&#43;------------&#43;-----&#43;------&#43;----------&#43;----------------------------&#43;
|user_id|server_id|mail_id |state|from |subject |content |
&#43;-------&#43;---------&#43;------------&#43;-----&#43;------&#43;----------&#43;----------------------------&#43;
|"10001"|1 |202106301221|0 |"系统"|"新手邮件"|"欢迎你&#xff0c;来到我们的虚拟世界"|
&#43;-------&#43;---------&#43;------------&#43;-----&#43;------&#43;----------&#43;----------------------------&#43;
1 records selected, select time: 41306 us
如果要列显示&#xff1a;
tcaplus> select * from mail where user_id &#61; "10001" \\G;
user_id: "10001"
server_id: 1
mail_id: 202106301221
state: 0
from: "系统"
subject: "新手邮件"
content: "欢迎你&#xff0c;来到我们的虚拟世界"
1 records selected, select time: 5450 us
更新&#xff1a;
tcaplus> update mail set state &#61; 1, from &#61; "系统2" where user_id &#61; "10001" and server_id &#61; 1 and mail_id&#61;202106301221;
update success
update time: 7497 us
删除&#xff1a;
tcaplus> delete from mail where user_id &#61; "10001" and server_id &#61; 1 and mail_id&#61;202106301221;
delete success
delete time: 5367 us
如果要通过部分key 删除符合条件的记录&#xff0c;如下使用&#xff1a;
tcaplus> delete from mail where user_id &#61; "10001" and server_id &#61; 1 by partkey;
delete success
delete time: 8567 us
导出
tcaplus> dump * into mail.txt from mail limit 10;
会导出到本目录下&#xff0c;打开后&#xff0c;内容如下&#xff1a;
[root&#64;VM_0_13_centos bin]# cat mail.txt
user_id,server_id,mail_id,state,from,subject,content
"10001",1,202106301221,0,"系统","新手邮件","欢迎你&#xff0c;来到我们的虚拟世界"
导入
tcaplus> load mail infile mail.txt;
loaded 1 records successful
索引查询
当开启全局索引功能后&#xff0c;TcaplusDB 将支持按照普通字段查询&#xff0c;查询条件中的字段必须是建立了全局索引的字段。
如果是聚合查询&#xff0c;那么聚合查询的字段也必须是建立了全局索引的字段。
一个索引查询请求&#xff0c;最多返回3000条记录。
支持的查询语句
条件查询
支持&#61;, >, >&#61;, <, <&#61;, !&#61;, between, in, not in, like, not like, and, or
聚合查询
当前支持的聚合查询包括&#xff1a;sum, count, max, min, avg&#xff0c;如&#xff1a;
以下两个指令要等到3.51.0才能支持
设置生命周期
毫秒级别
tcaplus> setttl mail ttl&#61;60000 where user_id &#61; "10001" and server_id &#61; 1 and mail_id&#61;"202106301221";
读取生命周期
tcaplus> getttl from mail where user_id &#61; "10001" and server_id &#61; 1 and mail_id&#61;"202106301221";
退出
tcaplus> exit
当你不知道某个指令如何使用时&#xff0c;可以用help 前缀看帮助内容&#xff1a;
help select
参考链接&#xff1a;游戏数据库TcaplusDB
TcaplusDB是腾讯出品的分布式NoSQL数据库&#xff0c;存储和调度的代码完全自研。具备缓存&#43;落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。