1, the background

LBS (Location Based Service) has a wide range of application scenarios. The most common application is the query of Point of Interest (POI), for example, users search for nearby people, nearby restaurants, nearby take-out shops and so on. The realization of LBS requires database to store geographic location information. Open source Redis is a cache database with strong function, high efficiency and easy to use, which realizes the function of geographic location storage and can be used for LBS data storage.

The open source Redis 3.2 + Geo feature supports geo-location information storage and management, but memory constraints prevent large-scale application. GaussDB(for Redis) (gauss ****Redis for short) is compatible with the Geo function of open source Redis. It uses disks to replace memory, breaking the memory limit of open source Redis and perfectly solving the problem of large-scale Geo applications.

2. Introduction to open source Redis Geo

Redis Geo supports the following six Geo operations:

  • Geoadd: Adds the coordinates of a geographic location.

  • Geopos: To obtain the coordinates of a geographical location.

  • Geodist: Retrieves the distance between two geographical locations.

  • Geohash: Retrieves the geohash value for a geographic location.

  • Georadius: Obtain the geographic location set within the specified range according to the given geographic location coordinates.

  • Georadiusbymember: Gets a set of geographic locations within a specified range based on a given geographic location.

The spatial index of Redis Geo function adopts GeoHash principle and zset storage, with query efficiency approaching log(N).

2. Why is open source Redis Geo not widely used?

The application of storing geographic location information is very extensive, and the open source Redis Geo function can also store geographic location information, and the query efficiency is high, why has not been a large-scale application?

Scenarios for analyzing and storing geographic location information have the following characteristics:

  • Large amount of data

In most scenarios, the amount of data for storing geographic location information is above TB level. All data of open source Redis is stored in memory. The memory size of nodes is fixed.

  • Data continues to grow

As the number of users increases, the data of geographic location information also increases, requiring the capacity of the underlying storage to be expanded without damage. However, the expansion of open source Redis requires redivision of hash slots for data migration, which will inevitably affect services.

  • High concurrent read and write

In open source Redis master-slave mode, only the master node can be written, and the master node has high concurrent data write and read. If the write speed is too high, it is easy to cause master-slave accumulation and data loss.

In addition, you need to consider database system capabilities such as backup and recovery, data consistency, capacity expansion, and high availability.

  • Backup recovery

The open source Redis provides DATA backup in RDB and AOF modes. However, when the data scale is large, the data consistency and integrity of data recovery in RDB mode are poor, and the efficiency of data recovery in AOF mode is low.

  • Data consistency

The master and slave of open source Redis adopt asynchronous replication, which may cause data inconsistency.

  • High availability

If open source Redis fails a pair of primary and secondary nodes at the same time, part of the data will be unavailable and the fault tolerance is weak.

3. Why is Gauss Redis appropriate?

Gauss Redis is based on huawei distributed storage system DFV and supports pB-level large-scale data storage. It solves the problems of open source Redis, such as high cost, small amount of stored data, data inconsistency and so on. It has the advantages of second capacity expansion, super availability, strong consistency, low cost, automatic backup and strong write resistance.

4. Applicable Scenarios

The Gauss Redis Geo function applies to scenarios with a large amount of data and frequent read and write operations. In the takeout platform, review platform and housing search platform, the data of restaurants, takeout riders, users and housing sources will exceed 100 million with the growth of users, and the data amount of corresponding geographical location information can reach several TB level, which is exactly the scenario applicable to Gauss Redis. The following describes how to use the Geo function in different scenarios.

4.1 Take-out Scenario:

(1) After placing the takeout order, the user uses the geoadd command to add the location of the rider.

(2) Geopos allows the user to obtain the location of a rider.

(3) Use Georadius/Georadiusbymember to command the rider to check nearby orders that can be delivered.

(4) The user can obtain the distance of the rider by using the geodist command.

4.2 Review Scenarios:

(1) Add a new store to the review platform and use the geoadd command to add the location of the new store.

(2) Using geopos, the user obtains the location of the store.

(3) By using the geodist command, the user can obtain the distance from the store.

(4) By using Georadius/GeoradiusBymember, users can find stores within a distance of 500 meters.

4.3 Housing Search Scenario:

(1) Add the new house to the house platform and use the geoadd command to add the location of the new house.

(2) Geopos allows users to obtain the locations of houses.

(3) By using the geodist command, users can obtain the distance from the house source.

(4) With the command georadius/ Georadiusbymember, users can search for houses within 1km.

5, summary

The Geo function of open source Redis has high query efficiency, but it has obvious shortcomings such as small storage capacity, weak anti-write ability and poor availability, leading to its Geo function has not been widely used. Gaussian Redis breaks through the memory limitation of open source Redis, and stores data on high-performance disks. It has the characteristics of second expansion, super availability, strong consistency, low cost, automatic backup and strong write resistance. Therefore, Gaussian Redis is suitable for the scenario where a large amount of geographical location information is stored.

End of 6,

Author: Huawei Cloud Gauss Redis team.

Hangzhou Xi ‘an Shenzhen resume: [email protected]

Pay more attention to technical articles, gaussian Redis official blog: bbs.huaweicloud.com/community/u…