【问题标题】:How to remove an item from a redis geohash?如何从 redis geohash 中删除项目?
【发布时间】:2017-01-08 07:12:12
【问题描述】:

Redis 3.2 具有 geohash 类型。

GEOADD is used to add keys:

> GEOADD restaurants 32.0 34.0 Falafel
(integer) 1
> GEOADD restaurants 32.1 34.1 Pizza
(integer) 1

GEORADIUS 用于进行地理查询:

> GEORADIUS restaurants 32.05 34.05 100 km WITHDIST
1) 1) "Falafel"
   2) "7.2230"
2) 1) "Pizza"
   2) "7.2213"

但是,HDEL 似乎不起作用:

> HDEL restaurants Falafel
(error) WRONGTYPE Operation against a key holding the wrong kind of value

如何删除或设置 TTL 到地理哈希中的键?

【问题讨论】:

    标签: hash redis geo redis-3.2


    【解决方案1】:

    Geohashes 是排序集,所以 right command is ZREM:

    > ZREM restaurants Falafel
    (integer) 1
    
    > GEORADIUS restaurants 32.05 34.05 100 km WITHDIST
    1) 1) "Pizza"
       2) "7.2213"
    

    【讨论】:

    • 不,你没有错过。你忘了回答关于 TTL 的问题(结构中的成员没有 TTL)
    • 如何全部删除?
    • 等等,这有多奇怪,您可以使用值删除?这是否意味着它将独立于坐标删除所有Falafel? Redis 看起来很奇怪……
    • 哦,我试过了,原来你只能有一个Falafel,不过比我还奇怪。我想知道如何在实践中使用它。
    猜你喜欢
    • 2019-12-12
    • 2021-10-19
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2017-02-14
    相关资源
    最近更新 更多