Справочный веб-сайт
- Команда Redis
- Операция PHP redis
Экологические требования
Во-первых, убедитесь, что redis установлен и запущен
Убедитесь, что в PHP установлено расширение redis
php -m | grep redis
Общий список команд, связанных с redis
- ГЕО ДОБАВИТЬ
- ГЕОДЕЗИСТ
- ГЕОРАДИЙ
- ГЕОРАДИУСБИМЕМБЕРИ
- ГЕОХАШ
Команда вставки Geoadd
Команда: гео добавить ключевой элемент широты долготы [элемент широты долготы… ]
Detailed command -As the name suggests, this is an add command 1. Add data to an ordered set of geo types 2. Multiple parameters can be added at the same time. 3. Latitude and longitude limit The effective longitude is between - 180 and 180 degrees The effective latitude is between - 85.05112878 and 85.05112878 2. Return the space element successfully added to the key does not contain the existing but updated element. Be careful: 1. The longitude must be in the form of X, y before and after the disaster.
Использование команд
-Open client first 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 object $redis = new \Redis(); //Link redis native host address default port number $redis->connect('127.0.0.1', 6379); //Insert correct data $successRes = $redis->geoAdd( 'myplace', // key value 116.580799, 39.929301, 'me', // longitude and latitude of the first element and 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 [участник… ]
Сведения о команде:
-Get location Baidu translation says POS may be the abbreviation of location 1. Return the position of the given element in a key 2. Multiple parameters can be passed 3. Each item of the return parameter consists of two elements. The first element is longitude and the second element is latitude. 4. Return nil if the given element does not exist
Использование команд
Proper use # geopos myplace me you other Error using to get a nonexistent element # geopos myplace one
Использование в PHP
//Instantiate redis object $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 ); //Get error data $faildRes = $redis->geoPos( 'myplace', // key value 'one' // element does not exist ); var_dump($successRes); var_dump($faildRes);
Геодезист получает расстояние между двумя элементами
Команда: ключ геодезиста член1 член2 [единица измерения]
Detailed command -Get the distance between two elements dist distance 1. Fixed parameter can only calculate the distance between two elements 2. The last parameter unit stands for meter (m) by default. It has the following parameters M is in meters. Km is expressed in kilometers. Mi means miles. FT is in feet Return value: the calculated distance will be returned as a double precision floating-point number. If the given location element (any one) does not exist, the command returns a null value. Note: this command assumes that the earth is perfectly spherical when calculating the distance, which can cause a maximum error of 0.5% in extreme cases
Использование команд
Get the distance between two elements in meters # geodist myplace me you m Error using to get an element that does not exist # geodist myplace me not m
Использование в PHP
//Instantiate redis object $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 ); //Get bad data $faildRes = $redis->geoDist( 'myplace', // key value 'me', // element 'not' // nonexistent element ); var_dump($successRes); var_dump($faildRes);
Гордиус получает все элементы, которые не превышают определенного расстояния указанной широты и долготы
Команда: георадиус ключ долгота широта радиус м|км|фут|ми [с прохладной] [белая тарелка] [с хэшем] [asc|desc] [количество, количество]
Command details: -Get the element information of a radius within the specified latitude and longitude radius 1. Longitude and latitude must be specified before and after 2. The range unit can be specified as follows M is in meters Km is expressed in kilometers Mi is in miles FT is in feet 3. To obtain the distance between the given latitude and longitude, the parameter withdist unit is the same as the given distance unit. 4. The parameter withcoord is required to obtain the longitude and latitude of the return element. 5. Can use distance to sort ASC from near to far desc from far to near 6. Quantity returned Return value: returns an array
Использование команд
Get all elements in an element at a specific distance from a given coordinate. Display the distance. Display the coordinates from near to far. # georadius myplace 116.578486 39.927244 200 km WITHCOORD WITHDIST ASC COUNT 3
Использование в PHP
//Instantiate redis object $redis = new \Redis(); //Link redis native host address default port number $redis->connect('127.0.0.1', 6379); $options [] = 'withdist'; // distance $options [] ='withcoord '; // latitude and longitude $options [] = 'ASC'; // sort asc|desc $options ['Count '] = 3; // number //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 получает все элементы, которые не превышают определенного расстояния от указанного элемента
Команда: geardaiusbymember радиус ключевого элемента, м|км|фут|ми [с прохладой] [с тарелкой] [с хэшем] [asc|desc] [количество, количество]
Detailed command -Get the element within the specified distance according to one element in the key value, which is equivalent to another version of the geordius command. 1. You need to specify elements instead of latitude and longitude Note: the element must be an existing element in the key value. The return value will also contain the selected element Return value: array
Использование команд
Get the selected elements within the specified range of an element me distance 200 unit m return distance longitude and latitude from near to far 3 # georadiusbymember myplace me 200 m WITHCOORD WITHDIST ASC COUNT 3
Использование в PHP
//Instantiate redis object $redis = new \Redis(); //Link redis native host address default port number $redis->connect('127.0.0.1', 6379); $options [] = 'withdist'; // distance $options [] ='withcoord '; // latitude and longitude $options [] = 'ASC'; // sort asc|desc $options ['Count '] = 3; // number //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 [участник… ]
Detailed command -Get the hash value of Geo 1. The hash value of multiple elements can be obtained at the same time Note: the returned data needs to be mapped by itself Return value: each item of an array is a geohash
Использование команд
Get geohash # geohash myplace me you other
Использование PHP
//Instantiate redis object $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);