Tile38空间数据库操作命令之删除操作

简介: Tile38空间数据库操作命令之删除操作

DEL语法

DEL key id
复制代码

删除指定的对象。

  • 示例:
127.0.0.1:9851> SET fleet truck1 POINT 116.578497 39.868634
{"ok":true,"elapsed":"17.493µs"}
127.0.0.1:9851> GET fleet truck1
{"ok":true,"object":{"type":"Point","coordinates":[39.868634,116.578497]},"elapsed":"14.437µs"}
127.0.0.1:9851> DEL fleet truck1
{"ok":true,"elapsed":"11.662µs"}
127.0.0.1:9851> GET fleet truck1
(error) id not found
复制代码
  • 1.我们先设置一个id=truck1的POINT数据;
    2.通过查询语句可以确定我们设置好的数据;
    3.通过DEL删除数据;
    4.通过GET确定是否真的被删除;

JDEL语法

JDEL key id path
复制代码

JDEL命令用来操作JSON文档的,它可以根据提供的path来删除JSON文档里面的数据;

  • 示例:
127.0.0.1:9851> JSET user 901 name.first Tom
{"ok":true,"elapsed":"53.761µs"}
127.0.0.1:9851> JSET user 901 name.last Anderson
{"ok":true,"elapsed":"33.783µs"}
127.0.0.1:9851> JGET user 901
{"ok":true,"value":"{"name":{"first":"Tom","last":"Anderson"}}","elapsed":"26.67µs"}
127.0.0.1:9851> JDEL user 901 name.last
{"ok":true,"elapsed":"68.749µs"}
127.0.0.1:9851> JGET user 901
{"ok":true,"value":"{"name":{"first":"Tom"}}","elapsed":"16.942µs"}
复制代码
  • 1.通过JSET创建JSON文档{"name":{"first":"Tom"}}
    2.通过JSET给文档添加last字段:{"name":{"first":"Tom","last":"Anderson"}}
    3.JGET查询确定添加后的结果;
    4.通过JDEL命令删除文档中的指定字段name.last
    5.查询删除后的结果:`{"name":{"first":"Tom"}}

PDEL语法

PDEL key pattern
复制代码

PDEL使用正则表达式来匹配id字段来删除目标数据;

  • 示例:
127.0.0.1:9851> SET fleet truck1 POINT 116.582268 39.867757
{"ok":true,"elapsed":"22.141µs"}
127.0.0.1:9851> SET fleet hello POINT 116.577703 39.867514
{"ok":true,"elapsed":"16.842µs"}
127.0.0.1:9851> SET fleet truco POINT 116.578497 39.868634
{"ok":true,"elapsed":"14.938µs"}
127.0.0.1:9851> SCAN fleet
{"ok":true,"objects":[{"id":"hello","object":{"type":"Point","coordinates":[39.867514,116.577703]}},{"id":"truck1","object":{"type":"Point","coordinates":[39.867757,116.582268]}},{"id":"truco","object":{"type":"Point","coordinates":[39.868634,116.578497]}}],"count":3,"cursor":0,"elapsed":"74.791µs"}
127.0.0.1:9851> PDEL fleet truc*
{"ok":true,"elapsed":"14.978µs"}
127.0.0.1:9851> SCAN fleet
{"ok":true,"objects":[{"id":"hello","object":{"type":"Point","coordinates":[39.867514,116.577703]}}],"count":1,"cursor":0,"elapsed":"81.773µs"}
复制代码
  • 1.SET命令先准备好数据;
    2.通过SCAN命令确定数据没有问题,一共是三个点位的数据;
    3.通过PDEL删除id以truc开头的数据;
    4.通过SCAN命令查看删除后的结果,最后只剩下一个点位的数据;

DELCHAN语法

DELCHAN name
复制代码

删除指定的频道;这个所谓的频道就是用来接收相关事件的,发布到频道上面的事件可以被客户端订阅消费;

  • 示例:
127.0.0.1:9851> SETCHAN warehouse NEARBY fleet FENCE POINT 33.5123 -112.2693 500
{"ok":true,"elapsed":"78.688µs"}
127.0.0.1:9851> CHANS warehouse
{"ok":true,"chans":[{"name":"warehouse","key":"fleet","ttl":-1,"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"16µs"}
127.0.0.1:9851> DELCHAN warehouse
{"ok":true,"elapsed":"20.719µs"}
127.0.0.1:9851> CHANS warehouse
{"ok":true,"chans":[],"elapsed":"6.362µs"}
复制代码
  • 1.先通过SETCHAN命令创建一个warehouse名称的频道;目标点500米范围内的,fleet中的任何数据对象在该范围内有变动,都会把相关事件发送到该频道;
    2.CHANS命令确定创建的频道没有问题;
    3.使用DELCHAN删除warehouse频道;
    4.确定warehouse频道删除成功;

PDELCHAN语法

PDELCHAN pattern
复制代码

有了前面的经验,这个命令我们就很容易就猜出来了:根据正则表达式来删除目标频道。

  • 示例:
127.0.0.1:9851> SETCHAN warehouse NEARBY fleet FENCE POINT 33.5123 -112.2693 500
{"ok":true,"elapsed":"78.688µs"}
127.0.0.1:9851> SETCHAN house NEARBY fleet FENCE POINT 33.5123 -112.2693 500
{"ok":true,"elapsed":"88.075µs"}
127.0.0.1:9851> CHANS warehouse
{"ok":true,"chans":[{"name":"warehouse","key":"fleet","ttl":-1,"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"16µs"}
127.0.0.1:9851> CHANS house
{"ok":true,"chans":[{"name":"house","key":"fleet","ttl":-1,"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"23.494µs"}
127.0.0.1:9851> PDELCHAN ware*
{"ok":true,"elapsed":"20.719µs"}
127.0.0.1:9851> CHANS warehouse
{"ok":true,"chans":[],"elapsed":"6.362µs"}
127.0.0.1:9851> CHANS house
{"ok":true,"chans":[{"name":"house","key":"fleet","ttl":-1,"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"23.494µs"}
复制代码
  • 1.先通过SETCHAN命令创建一个warehouse名称的频道;目标点500米范围内的,fleet中的任何数据对象在该范围内有变动,都会把相关事件发送到该频道;
    2.另外再创建一个house频道;
    2.CHANS命令确定创建的频道没有问题;
    3.使用PDELCHAN删除名称以ware开头的频道;
    4.确定名称以ware开头的频道删除成功;
    5.CHANS查看house频道还存在;

DELHOOK语法

DELHOOK name
复制代码

CHAN一样,HOOK是另外一种形式的监测形式,HOOK就是指定一个目标回调接口,有任何的事件都调用这个目标接口。

  • 示例:
127.0.0.1:9851> SETHOOK warehouse http://10.0.20.78/endpoint NEARBY fleet FENCE POINT 33.5123 -112.2693 500
{"ok":true,"elapsed":"104.456µs"}
127.0.0.1:9851> HOOKS warehouse
{"ok":true,"hooks":[{"name":"warehouse","key":"fleet","ttl":-1,"endpoints":["http://10.0.20.78/endpoint"],"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"23.033µs"}
127.0.0.1:9851> DELHOOK warehouse
{"ok":true,"elapsed":"31.941µs"}
127.0.0.1:9851> HOOKS warehouse
{"ok":true,"hooks":[],"elapsed":"24.506µs"}
复制代码
  • 1.通过SETHOOK创建一个warehouse为名称的HOOK
    2.查询warehouse HOOK创建成功;
    3.删除warehouse HOOK;
    4.查询是否还存在warehouse HOOK;

PDELHOOK语法

PDELHOOK pattern
复制代码

PDELHOOK很明确,就是通过正则表达式来删除目标HOOK

  • 示例:
127.0.0.1:9851> SETHOOK warehouse http://10.0.20.78/endpoint NEARBY fleet FENCE POINT 33.5123 -112.2693 500
{"ok":true,"elapsed":"104.456µs"}
127.0.0.1:9851> SETHOOK house http://127.0.0.1/endpoint NEARBY fleet FENCE POINT 33.5123 -112.2693 500
{"ok":true,"elapsed":"98.134µs"}
127.0.0.1:9851> HOOKS warehouse
{"ok":true,"hooks":[{"name":"warehouse","key":"fleet","ttl":-1,"endpoints":["http://10.0.20.78/endpoint"],"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"23.033µs"}
127.0.0.1:9851> HOOKS house
{"ok":true,"hooks":[{"name":"house","key":"fleet","ttl":-1,"endpoints":["http://127.0.0.1/endpoint"],"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"23.904µs"}
127.0.0.1:9851> PDELHOOK ware*
{"ok":true,"elapsed":"31.941µs"}
127.0.0.1:9851> HOOKS warehouse
{"ok":true,"hooks":[],"elapsed":"24.506µs"}
127.0.0.1:9851> HOOKS house
{"ok":true,"hooks":[{"name":"house","key":"fleet","ttl":-1,"endpoints":["http://127.0.0.1/endpoint"],"command":["NEARBY","fleet","FENCE","POINT","33.5123","-112.2693","500"],"meta":{}}],"elapsed":"23.904µs"}
复制代码
  • 1.通过SETHOOK创建两个不同的HOOK,一个名称叫warehouse,一个叫house
    2.确定两个HOOK都创建成功,没有问题;
    3.通过PDELHOOK命令删除以ware开头的HOOK
    4.再次查看,发现warehouse被删除,而house作为名称的HOOK没有被删除;

PERSIST语法

PERSIST key id
复制代码

删除指定id数据对象里面的超时设置,也就是EX配置;执行PERSIST后,目标id对应的TTL字段值为-1;

  • 示例:
127.0.0.1:9851> SET fleet time EX 10 POINT 116.578497 39.868634
{"ok":true,"elapsed":"17.873µs"}
127.0.0.1:9851> TTL fleet time
{"ok":true,"ttl":7.895136745,"elapsed":"8.877µs"}
127.0.0.1:9851> PERSIST fleet time
{"ok":true,"elapsed":"5.51µs"}
127.0.0.1:9851> TTL fleet time
{"ok":true,"ttl":-1,"elapsed":"4.709µs"}
复制代码
  • 1.先创建一个带有EX属性的time名称的数据对象;
    2.使用TTL命令确定剩余的过期时间;
    3.使用PERSIST删除timeEX配置;
    4.再次查看过期时间,已经变为-1;

DROP语法

DROP key
复制代码

DROP直接删除一组数据对象;

  • 示例:
127.0.0.1:9851> SET fleet truck1 POINT 116.578497 39.868634
127.0.0.1:9851> SET fleet truck2 POINT 116.577703 39.867514
127.0.0.1:9851> SCAN fleet
{"ok":true,"objects":[{"id":"truck1","object":{"type":"Point","coordinates":[39.868634,116.578497]}},{"id":"truck2","object":{"type":"Point","coordinates":[39.867514,116.577703]}}],"count":2,"cursor":0,"elapsed":"81.944µs"}
127.0.0.1:9851> DROP fleet
{"ok":true,"elapsed":"9.067µs"}
127.0.0.1:9851> SCAN fleet
{"ok":true,"objects":[],"count":0,"cursor":0,"elapsed":"12.604µs"}
复制代码
  • 1.先在fleet中创建两个点位truck1truck2
    2.SCAN命令确定fleet中的点位都创建成功;
    3.使用DROP命令删除fleet
    4.确定删除操作成功;

FLUSHDB语法

FLUSHDB
复制代码

删除所有的键,该操作不需要带任何参数;其实就是清空数据库。

【注意】:这个命令将删除所有的数据。


相关文章
|
3月前
|
存储 关系型数据库 MySQL
初步了解MySQL数据库的基本命令
初步了解MySQL数据库的基本命令
46 0
|
1月前
|
tengine 关系型数据库 MySQL
Tengine、Nginx安装MySQL数据库命令教程
本指南详细介绍了在Linux系统上安装与配置MySQL数据库的步骤。首先通过下载并安装MySQL社区版本,接着启动MySQL服务,使用`systemctl start mysqld.service`命令。若启动失败,可尝试使用`sudo /etc/init.d/mysqld start`。利用`systemctl status mysqld.service`检查MySQL的服务状态,确保其处于运行中。通过日志文件获取初始密码,使用该密码登录数据库,并按要求更改初始密码以增强安全性。随后创建一个名为`tengine`的数据库,最后验证数据库创建是否成功以及完成整个设置流程。
|
1月前
|
NoSQL MongoDB 数据库
MongoDB是一个NoSQL数据库,有着多种不同的命令和操作。以下是一些常见的MongoDB命令:
一些常用的MongoDB命令,如数据库和集合的管理、数据的插入、查询、更新、删除以及聚合操作等。
25 1
|
2月前
|
关系型数据库 MySQL 数据库
6-2|测试连接数据库的命令
6-2|测试连接数据库的命令
|
1月前
|
SQL Shell 数据库
在TDengine容器中创建初始化数据库的Shell命令实例
以上就是在Docker容器环境中部署并初始化TDengine数据库的全过程,希望对你有所帮助。
66 0
|
4月前
|
NoSQL MongoDB 数据库
Mongo 数据库备份和恢复命令
Mongo 数据库备份和恢复命令
248 4
|
4月前
|
SQL 存储 数据挖掘
深入了解SQLite3命令:小巧强大的数据库工具
SQLite3是轻量级数据库工具,适用于嵌入式设备和数据分析。它提供交互式shell,无需服务器,易于部署。常用命令如`.schema`显示表结构,`.mode`设置输出格式。示例包括创建数据库`mydatabase.db`,创建表`users`,插入数据并查询。注意动态类型系统、性能限制及SQL注入安全。适合轻量级数据存储和管理。
|
4月前
|
Web App开发 缓存 数据管理
数据管理DMS使用问题之执行SHOW CREATE TABLE命令查看表结构时,数据库管理员和普通授权账号看到的为什么不一样
阿里云数据管理DMS提供了全面的数据管理、数据库运维、数据安全、数据迁移与同步等功能,助力企业高效、安全地进行数据库管理和运维工作。以下是DMS产品使用合集的详细介绍。
|
5月前
|
关系型数据库 MySQL 分布式数据库
PolarDB产品使用问题之 MySQL数据库中,执行delete命令删除数据后,存储空间通常不会立即释放,该如何优化
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。
135 2
|
4月前
|
NoSQL Java 数据库
数据库问题之使用jmap命令获取Java堆信息如何解决
数据库问题之使用jmap命令获取Java堆信息如何解决
34 0
下一篇
无影云桌面