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
删除time
的EX
配置;
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
中创建两个点位truck1
、truck2
;
2.SCAN
命令确定fleet
中的点位都创建成功;
3.使用DROP
命令删除fleet
;
4.确定删除操作成功;
FLUSHDB语法
FLUSHDB 复制代码
删除所有的键,该操作不需要带任何参数;其实就是清空数据库。
【注意】:这个命令将删除所有的数据。