///|
pub(all) struct GeoCoordinates {
longitude : Double
latitude : Double
}
///|
pub fn GeoCoordinates::to_array(self : GeoCoordinates) -> Array[String] {
[self.longitude.to_string(), self.latitude.to_string()]
}
///|
pub(all) enum GeoUnits {
Meters
Kilometers
Miles
Feet
}
///|
pub extend GeoUnits with Show::{to_string, output}
///|
pub(all) struct GeoSearchByBox {
width : Int32
height : Int32
unit : GeoUnits
}
///|
pub fn GeoSearchByBox::to_array(self : GeoSearchByBox) -> Array[String] {
[self.width.to_string(), self.height.to_string(), self.unit.to_string()]
}
///|
pub impl Show for GeoUnits with fn output(self : GeoUnits, logger : &Logger) -> Unit {
logger.write_string(self.to_string())
}
///|
pub impl Show for GeoUnits with fn to_string(self : GeoUnits) -> String {
match self {
Meters => "m"
Kilometers => "km"
Miles => "mi"
Feet => "ft"
}
}
// ============ 地理位置命令 ============
///|
pub async fn Client::geoadd(
self : Client,
key : String,
longitude : String,
latitude : String,
value : String,
) -> RedisInt {
self.send(["GEOADD", key, longitude, latitude, value]).to_int()
}
///|
pub async fn Client::geoadd_multiple(
self : Client,
key : String,
coordinates : Array[GeoCoordinates],
) -> RedisInt {
let args : Array[String] = Array(capacity=2 + coordinates.length() * 3)
args.push("GEOADD")
args.push(key)
for coordinate in coordinates {
args.append(coordinate.to_array())
}
self.send(args).to_int()
}
///|
pub async fn Client::geodist(
self : Client,
key : String,
member1 : String,
member2 : String,
) -> RedisBulkString {
self.send(["GEODIST", key, member1, member2]).to_bulk_string()
}
///|
pub async fn Client::geodist_unit(
self : Client,
key : String,
member1 : String,
member2 : String,
unit : GeoUnits,
) -> RedisBulkString {
self
.send(["GEODIST", key, member1, member2, unit.to_string()])
.to_bulk_string()
}
///|
pub async fn Client::geohash(
self : Client,
key : String,
members : Array[String],
) -> RedisArray {
let args = ["GEOHASH", key, ..members]
self.send(args).to_array()
}
///|
pub async fn Client::geopos(
self : Client,
key : String,
members : Array[String],
) -> RedisArray {
let args = ["GEOPOS", key, ..members]
self.send(args).to_array()
}
///|
pub async fn Client::georadius(
self : Client,
key : String,
longitude : String,
latitude : String,
radius : String,
unit : GeoUnits,
) -> RedisArray {
self
.send(["GEORADIUS", key, longitude, latitude, radius, unit.to_string()])
.to_array()
}
///|
pub async fn Client::georadius_ro(
self : Client,
key : String,
longitude : String,
latitude : String,
radius : String,
unit : GeoUnits,
) -> RedisArray {
self
.send(["GEORADIUS_RO", key, longitude, latitude, radius, unit.to_string()])
.to_array()
}
///|
pub async fn Client::georadiusbymember(
self : Client,
key : String,
value : String,
radius : String,
unit : GeoUnits,
) -> RedisArray {
self
.send(["GEORADIUSBYMEMBER", key, value, radius, unit.to_string()])
.to_array()
}
///|
pub async fn Client::georadiusbymember_ro(
self : Client,
key : String,
value : String,
radius : String,
unit : GeoUnits,
) -> RedisArray {
self
.send(["GEORADIUSBYMEMBER_RO", key, value, radius, unit.to_string()])
.to_array()
}
///|
pub async fn Client::geosearch(
self : Client,
key : String,
member_ : String,
radius : String,
unit : GeoUnits,
) -> RedisArray {
self
.send([
"GEOSEARCH",
key,
"FROMMEMBER",
member_,
"BYRADIUS",
radius,
unit.to_string(),
])
.to_array()
}
///|
pub async fn Client::geosearch_box(
self : Client,
key : String,
coordinates : GeoCoordinates,
search_box : GeoSearchByBox,
) -> RedisArray {
self
.send(
[
"GEOSEARCH",
key,
"FROMLONLAT",
..coordinates.to_array(),
"BYBOX",
..search_box.to_array(),
],
)
.to_array()
}
///|
pub async fn Client::geosearchstore(
self : Client,
source : String,
destination : String,
member_ : String,
radius : String,
unit : GeoUnits,
) -> RedisInt {
self
.send([
"GEOSEARCHSTORE",
source,
destination,
"FROMMEMBER",
member_,
"BYRADIUS",
radius,
unit.to_string(),
])
.to_int()
}
///|
pub async fn Client::geosearchstore_with_dist(
self : Client,
destination : String,
source : String,
member_ : String,
radius : Double,
unit : GeoUnits,
) -> RedisInt {
self
.send([
"GEOSEARCHSTORE",
destination,
source,
"FROMMEMBER",
member_,
"BYRADIUS",
radius.to_string(),
unit.to_string(),
"STOREDIST",
])
.to_int()
}
///|
pub async fn Client::geosearch_with_dist(
self : Client,
key : String,
member_ : String,
radius : Double,
unit : GeoUnits,
) -> RedisArray {
self
.send([
"GEOSEARCH",
key,
"FROMMEMBER",
member_,
"BYRADIUS",
radius.to_string(),
unit.to_string(),
"WITHDIST",
])
.to_array()
}
///|
pub async fn Client::geosearchstore_box(
self : Client,
destination : String,
source : String,
from_member : String,
search_box : GeoSearchByBox,
) -> RedisInt {
self
.send(
[
"GEOSEARCHSTORE",
destination,
source,
"FROMMEMBER",
from_member,
"BYBOX",
..search_box.to_array(),
],
)
.to_int()
}