Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all locations saved in geoset in redis?

I am saving coordinate points sent from mobile device to redis database through geo redis npm package, But their is no function to get path location in which it was saved as I need them to get total distance traveled by user.Also i want to move all the points in MySql database.

I am able to get all the points saved with geo set with the help of command

```127.0.0.1:6379> ZRANGE rideLocations:345 0 -1```

but all values I found are are encoded in geo format like this

```
 1) "1"
 2) "3484047800163752"
 3) "10"
 4) "3484047800163752"
 5) "2"
 6) "3484047800163752"
 7) "3"
 8) "3484047800163752"
 9) "4"
10) "3484047800163752"
11) "5"
12) "3484047800163752"
13) "6"
14) "3484047800163752"
15) "7"
16) "3484047800163752"
17) "8"
18) "3484047800163752"
19) "9"
20) "3484047800163752"
```

How can i get them in their real format{ lat: 23.234, lng: 45.5435 } or how can i convert them in their real format.

Or I any suggestion if I am storing in wrong type? How can I convert them before save into MySql. any command in nodejs.

like image 327
Prashant Barve Avatar asked Jul 15 '16 13:07

Prashant Barve


1 Answers

To retrieve all the coordinates just search the entire planet, i.e.:

redis> GEORADIUS rideLocations:345 0 0 22000 km WITHCOORD

Note, however, that your description of the problem does not include ordering of the locations, which makes calculating a path impossible.

like image 134
Itamar Haber Avatar answered Nov 14 '22 22:11

Itamar Haber