Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an item from a redis geohash?

Redis 3.2 feature the geohash type.

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 is used to make a geo query:

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

However, HDEL does not seem to work:

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

How do I delete, or set a TTL, to a key within a geo hash?

like image 304
Adam Matan Avatar asked Aug 31 '16 15:08

Adam Matan


1 Answers

Geohashes are sorted sets, so the right command is ZREM:

> ZREM restaurants Falafel
(integer) 1

> GEORADIUS restaurants 32.05 34.05 100 km WITHDIST
1) 1) "Pizza"
   2) "7.2213"
like image 196
Adam Matan Avatar answered Sep 22 '22 03:09

Adam Matan