Справочный веб-сайт
- Команда Redis
- Операция PHP redis
Экологические требования
Во-первых, убедитесь, что redis установлен и запущен
Убедитесь, что в PHP установлено расширение redis
php -m | grep redis
Обзор команд, связанных с redis
- ГЕО ДОБАВИТЬ
- ГЕОДЕЗИСТ
- ГЕОРАДИЙ
- ГЕОРАДИУСБИМЕМБЕРИ
- ГЕОХАШ
Команда вставки GEOADD
Команда: ГЕО ДОБАВИТЬ ключевой элемент долготы [элемент долготы] ]
Detailed command - As the name implies, this is an add command 1. Adding data to an ordered set of geo types 2. Multiple parameters can be passed and added at the same time 3. Longitudinal and Latitude Limitations Effective longitude ranges from - 180 degrees to 180 degrees Effective latitudes range from - 85.05112878 degrees to 85.05112878 degrees. 2. Returns the space element successfully added to the key that contains no existing but updated elements Be careful: 1. The longitude must be in accordance with the x, y format after the disaster in the first latitude.
Использование команд
- First open the client Correct addition # geoadd myplace 116.580799 39.929301 me 116.580691 39.929007 you 116.58101 39.928931 other Wrong demonstration # geoadd test 181 181 one
Вызовите PHP
// Instantiate redis objects $redis = new \Redis(); // Link redis native host address default port number $redis->connect('127.0.0.1', 6379); // Insert the correct data $successRes = $redis->geoAdd( 'myplace', // key value 116.580799, 39.929301,'me', // latitude and longitude of the first element and its corresponding name 116.580691,39.929007, 'you', 116.58101, 39.928931, 'other' ); // Insert error data $faildRes = $redis->geoAdd( 'test', 181, 181, 'one' ); var_dump($successRes); var_dump($faildRes);
GEOPOS Получает местоположение указанного элемента
Команда: Ключевой участник GEOPOS [участник… ]
Детали заказа:
- Baidu Translator said POS may be the abbreviation of location 1. Returns the location of a given element in a key 2. Parameters can be passed multiple times 3. Each item of the return parameter consists of two elements, the first element being longitude and the second element being latitude. 4. Return nil if no given element exists
Использование команд
Proper use # geopos myplace me you other Misuse to get a nonexistent element # geopos myplace one
Использование в PHP
// Instantiate redis objects $redis = new \Redis(); // Link redis native host address default port number $redis->connect('127.0.0.1', 6379); // Get the right data $successRes = $redis->geoPos( 'myplace', // key value 'me'// element name ); // Getting Error Data $faildRes = $redis->geoPos( 'myplace', // key value 'one'// nonexistent element ); var_dump($successRes); var_dump($faildRes);
ГЕОДЕЗИСТ Получает Расстояние между Двумя Элементами
Команда: Ключевой элемент ГЕОДЕЗИСТА 1 элемент 2 [единица измерения]
Detailed command - Get the distance between two elements dist distance 1. Fixed parameters can only calculate the distance between two elements. 2. The last parameter unit represents the unit of meters (m) by default, with the following parameters M denotes in meters. Km denotes kilometers. Mi means miles. FT is expressed in feet Return value: The calculated distance is returned as a double-precision floating-point number. If a given location element (any one) does not exist, the command returns a null value. Note: This command assumes that the Earth is a perfect sphere when calculating distance. In the extreme case, this assumption will result in a maximum error of 0.5%.
Использование команд
Get the distance between two elements in meters # geodist myplace me you m Misuse to get a non-existent element # geodist myplace me not m
Использование в PHP
// Instantiate redis objects $redis = new \Redis(); // Link redis native host address default port number $redis->connect('127.0.0.1', 6379); // Get the right data $successRes = $redis->geoDist( 'myplace', // key value 'me', // element 'you', // element 'm'//Distance Unit ); // Getting the wrong data $faildRes = $redis->geoDist( 'myplace', // key value 'me', // element 'not'// elements that do not exist ); var_dump($successRes); var_dump($faildRes);
ГЕОГРАФИЧЕСКИЙ РАДИУС Получает все элементы, которые не превышают заданную широту и долготу на заданном расстоянии
Команда: ГЕОРАДАРНЫЙ ключ радиус долготы, м | км | фут | ми [С КООРДИНАТАМИ] [С ПЫЛЬЮ] [С ХЭШЕМ] [ASC | DESC] [КОЛИЧЕСТВО, количество]
Order details: - Gets the radius radius of the element information of a radius in the specified latitude and longitude 1. Longitude and longitude must be specified at the front and the rear latitudes. 2. The scope units may be designated as follows M denotes in meters Km denotes kilometers Mi means miles FT is expressed in feet 3. Getting the distance from a given latitude and longitude requires the same WITHDIST unit as the given distance unit. 4. Getting the latitude and longitude of the returned element requires the parameter WITHCOORD 5. Distance can be used to sort ASC from near to far DESC from far to near 6. Number of returns Return value: Returns an array
Использование команд
Get the display distance of all elements in an element from a given coordinate at a specified distance. Display coordinates according to three items from near to far. # georadius myplace 116.578486 39.927244 200 km WITHCOORD WITHDIST ASC COUNT 3
Использование в PHP
// Instantiate redis objects $redis = new \Redis(); // Link redis native host address default port number $redis->connect('127.0.0.1', 6379); $options []='WITHDIST'; // Distance $options []='WITHCOORD'; //longitude and latitude $options []='ASC'; //Sort ASC | DESC $options ['COUNT'] = 3; // number of entries // Get the right data $successRes = $redis->geoRadius( 'myplace', // key value '116.578486', //longitude '39.927244', //latitude '200', //Distance 'km', // Distance Unit $options // other optional parameters ); var_dump($successRes);
GEORADIUSBYMEMBER Получает все элементы, которые не превышают заданное расстояние до указанного элемента
Команда: ГЕОРАДИУСВЫБИРАЕМ ключевой элемент радиус м | км | фут | ми [С КООРДИНАТАМИ] [С ПЫЛЬЮ] [С ХЭШЕМ] [ASC | DESC] [КОЛИЧЕСТВО отсчетов]
Detailed command - Gets another version of the GEORADIUS command that corresponds to an element within a specified distance based on one of the key values 1. You need to specify elements instead of latitude and longitude. Note: The element must be an element that already exists in the key value and the return value of the element will also contain the selected element. Return value: array
Использование команд
Get the selected element me within the specified range of an element 200 units m, return distance longitude and latitude from near to far 3 # georadiusbymember myplace me 200 m WITHCOORD WITHDIST ASC COUNT 3
Использование в PHP
// Instantiate redis objects $redis = new \Redis(); // Link redis native host address default port number $redis->connect('127.0.0.1', 6379); $options []='WITHDIST'; // Distance $options []='WITHCOORD'; //longitude and latitude $options []='ASC'; //Sort ASC | DESC $options ['COUNT'] = 3; // number of entries // Get the right data $successRes = $redis->geoRadiusByMember( 'myplace', // key value 'me', // element '200', //Distance 'km', // Distance Unit $options // other optional parameters ); var_dump($successRes);
GEOHASH Получает значение гео-хэша элемента
Команда: Ключевой участник GEOHASH [участник… ]
Detailed command - Get the hash value of Geo 1. Hash values of multiple elements can be obtained simultaneously Note: The returned data needs to correspond to itself Return value: Each item of an array is a geohash
Использование команд
Get geohash # geohash myplace me you other
Использование PHP
// Instantiate redis objects $redis = new \Redis(); // Link redis native host address default port number $redis->connect('127.0.0.1', 6379); // Get the right data $successRes = $redis->geoHash( 'myplace', // key value 'me', // element 'you', // element 'other' // element ); var_dump($successRes);