use futures::Future;
use crate::{
commands,
error::RedisError,
interfaces::{ClientLike, RedisResult},
types::{
Any,
FromRedis,
GeoPosition,
GeoUnit,
MultipleGeoValues,
MultipleValues,
RedisKey,
RedisValue,
SetOptions,
SortOrder,
},
};
use std::convert::TryInto;
pub trait GeoInterface: ClientLike + Sized {
fn geoadd<R, K, V>(
&self,
key: K,
options: Option<SetOptions>,
changed: bool,
values: V,
) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
V: Into<MultipleGeoValues> + Send,
{
async move {
into!(key, values);
commands::geo::geoadd(self, key, options, changed, values)
.await?
.convert()
}
}
fn geohash<R, K, V>(&self, key: K, members: V) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<RedisError> + Send,
{
async move {
into!(key);
try_into!(members);
commands::geo::geohash(self, key, members).await?.convert()
}
}
fn geopos<R, K, V>(&self, key: K, members: V) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<RedisError> + Send,
{
async move {
into!(key);
try_into!(members);
commands::geo::geopos(self, key, members).await?.convert()
}
}
fn geodist<R, K, S, D>(
&self,
key: K,
src: S,
dest: D,
unit: Option<GeoUnit>,
) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
S: TryInto<RedisValue> + Send,
S::Error: Into<RedisError> + Send,
D: TryInto<RedisValue> + Send,
D::Error: Into<RedisError> + Send,
{
async move {
into!(key);
try_into!(src, dest);
commands::geo::geodist(self, key, src, dest, unit).await?.convert()
}
}
fn georadius<R, K, P>(
&self,
key: K,
position: P,
radius: f64,
unit: GeoUnit,
withcoord: bool,
withdist: bool,
withhash: bool,
count: Option<(u64, Any)>,
ord: Option<SortOrder>,
store: Option<RedisKey>,
storedist: Option<RedisKey>,
) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
P: Into<GeoPosition> + Send,
{
async move {
into!(key, position);
commands::geo::georadius(
self, key, position, radius, unit, withcoord, withdist, withhash, count, ord, store, storedist,
)
.await?
.convert()
}
}
fn georadiusbymember<R, K, V>(
&self,
key: K,
member: V,
radius: f64,
unit: GeoUnit,
withcoord: bool,
withdist: bool,
withhash: bool,
count: Option<(u64, Any)>,
ord: Option<SortOrder>,
store: Option<RedisKey>,
storedist: Option<RedisKey>,
) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
V: TryInto<RedisValue> + Send,
V::Error: Into<RedisError> + Send,
{
async move {
into!(key);
try_into!(member);
commands::geo::georadiusbymember(
self,
key,
to!(member)?,
radius,
unit,
withcoord,
withdist,
withhash,
count,
ord,
store,
storedist,
)
.await?
.convert()
}
}
fn geosearch<R, K>(
&self,
key: K,
from_member: Option<RedisValue>,
from_lonlat: Option<GeoPosition>,
by_radius: Option<(f64, GeoUnit)>,
by_box: Option<(f64, f64, GeoUnit)>,
ord: Option<SortOrder>,
count: Option<(u64, Any)>,
withcoord: bool,
withdist: bool,
withhash: bool,
) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
{
async move {
into!(key);
commands::geo::geosearch(
self,
key,
from_member,
from_lonlat,
by_radius,
by_box,
ord,
count,
withcoord,
withdist,
withhash,
)
.await?
.convert()
}
}
fn geosearchstore<R, D, S>(
&self,
dest: D,
source: S,
from_member: Option<RedisValue>,
from_lonlat: Option<GeoPosition>,
by_radius: Option<(f64, GeoUnit)>,
by_box: Option<(f64, f64, GeoUnit)>,
ord: Option<SortOrder>,
count: Option<(u64, Any)>,
storedist: bool,
) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
D: Into<RedisKey> + Send,
S: Into<RedisKey> + Send,
{
async move {
into!(dest, source);
commands::geo::geosearchstore(
self,
dest,
source,
from_member,
from_lonlat,
by_radius,
by_box,
ord,
count,
storedist,
)
.await?
.convert()
}
}
}