#![cfg(feature = "geospatial")]
use redis;
#[macro_use]
extern crate assert_approx_eq;
use redis::geo::{Coord, RadiusOptions, RadiusOrder, RadiusSearchResult, Unit};
use redis::{Commands, RedisResult};
mod support;
use crate::support::*;
const PALERMO: (&str, &str, &str) = ("13.361389", "38.115556", "Palermo");
const CATANIA: (&str, &str, &str) = ("15.087269", "37.502669", "Catania");
const AGRIGENTO: (&str, &str, &str) = ("13.5833332", "37.316667", "Agrigento");
#[test]
fn test_geoadd_single_tuple() {
let ctx = TestContext::new();
let mut con = ctx.connection();
assert_eq!(con.geo_add("my_gis", PALERMO), Ok(1));
}
#[test]
fn test_geoadd_multiple_tuples() {
let ctx = TestContext::new();
let mut con = ctx.connection();
assert_eq!(con.geo_add("my_gis", &[PALERMO, CATANIA]), Ok(2));
}
#[test]
fn test_geodist_existing_members() {
let ctx = TestContext::new();
let mut con = ctx.connection();
assert_eq!(con.geo_add("my_gis", &[PALERMO, CATANIA]), Ok(2));
let dist: f64 = con
.geo_dist("my_gis", PALERMO.2, CATANIA.2, Unit::Kilometers)
.unwrap();
assert_approx_eq!(dist, 166.2742, 0.001);
}
#[test]
fn test_geodist_support_option() {
let ctx = TestContext::new();
let mut con = ctx.connection();
assert_eq!(con.geo_add("my_gis", &[PALERMO, CATANIA]), Ok(2));
// We should be able to extract the value as an Option<_>, so we can detect
// if a member is missing
let result: RedisResult