Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Add lua and geo* support #69

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fred"
version = "1.2.2"
version = "1.3.0"
authors = ["Alec Embke <[email protected]>"]
edition = "2018"
description = "A Redis client for Rust built on Futures and Tokio."
Expand Down Expand Up @@ -33,9 +33,6 @@ tokio-proto = "0.1.1"
tokio-io = "0.1.12"
rand = "0.3"

[dev-dependencies]
hyper = "0.11"

[lib]
doc = true
doctest = false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ cargo add fred
* Built-in tracking for network latency and payload size metrics.
* Built-in mocking layer for running tests without a Redis server.
* A client pooling interface to round-robin requests among a pool of connections.
* Supports Lua scripts.

## Example

Expand Down Expand Up @@ -145,7 +146,6 @@ Note a local Redis server must be running on port 6379 and a clustered deploymen
* Blocking commands.
* Distribute reads among slaves.
* Transactions.
* Lua.

## Contributing

Expand Down
3 changes: 1 addition & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ cargo run --example basic
3. [Pubsub](pubsub.rs) - How to use the [publish-subscribe](https://redis.io/topics/pubsub) interface.
4. [Cluster](cluster.rs) - How to use with clustered Redis deployments.
5. [Multiple](multiple.rs) - An example that creates multiple clients on an event loop and composes their connections and commands together.
6. [Http](http.rs) - An example using a Redis client with a [hyper http server](https://github.com/hyperium/hyper).
7. [TLS](tls.rs) - An example showing how to use the TLS features.
6. [TLS](tls.rs) - An example showing how to use the TLS features.
134 changes: 0 additions & 134 deletions examples/http.rs

This file was deleted.

108 changes: 108 additions & 0 deletions src/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,32 @@ pub trait RedisClientBorrowed {

fn pttl<K: Into<RedisKey>>(&self, key: K) -> Box<Future<Item=i64, Error=RedisError>>;

fn script_load<S: Into<String>>(&self, script: S) -> Box<Future<Item=String, Error=RedisError>>;

fn script_flush(&self) -> Box<Future<Item=(), Error=RedisError>>;

fn script_exists<S: Into<MultipleKeys>>(&self, sha1: S) -> Box<Future<Item=Vec<bool>, Error=RedisError>>;

fn evalsha<S: Into<String>, K: Into<MultipleKeys>, V: Into<MultipleValues>>(&self, sha1: S, keys: K, args: V) -> Box<Future<Item=Vec<RedisValue>, Error=RedisError>>;
Copy link

@RicoGit RicoGit Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be more readable with where clause.


fn geoadd<K: Into<RedisKey>, V: Into<MultipleGeoValues>>(&self, key: K, values: V) -> Box<Future<Item=usize, Error=RedisError>>;

fn geohash<K: Into<RedisKey>, V: Into<MultipleValues>>(&self, key: K, values: V) -> Box<Future<Item=Vec<String>, Error=RedisError>>;

fn geopos<K: Into<RedisKey>, V: Into<MultipleValues>>(&self, key: K, values: V) -> Box<Future<Item=Vec<Option<(Longitude, Latitude)>>, Error=RedisError>>;

fn geodist<K: Into<RedisKey>, M: Into<RedisValue>, N: Into<RedisValue>>(&self, key: K, member1: M, member2: N, unit: Option<GeoUnit>) -> Box<Future<Item=Option<f64>, Error=RedisError>>;

fn georadius<K: Into<RedisKey>>(&self, key: K, longitude: Longitude, latitude: Latitude, radius: f64, unit: GeoUnit,
withcoord: bool, withdist: bool, withhash: bool, count: Option<usize>,
order: Option<GeoOrdering>, store: Option<String>, storedist: Option<String>)
-> Box<Future<Item=Vec<RedisValue>, Error=RedisError>>;

fn georadiusbymember<K: Into<RedisKey>, V: Into<RedisValue>>(&self, key: K, member: V, radius: f64, unit: GeoUnit,
withcoord: bool, withdist: bool, withhash: bool, count: Option<usize>,
order: Option<GeoOrdering>, store: Option<String>, storedist: Option<String>)
-> Box<Future<Item=Vec<RedisValue>, Error=RedisError>>;

}


Expand Down Expand Up @@ -825,6 +851,88 @@ impl RedisClientBorrowed for RedisClient {
commands::pttl(&self.inner, key)
}

/// Load a script into the scripts cache, without executing it.
///
/// <https://redis.io/commands/script-load>
fn script_load<S: Into<String>>(&self, script: S) -> Box<Future<Item=String, Error=RedisError>> {
commands::script_load(&self.inner, script)
}

/// Flush the Lua scripts cache.
///
/// <https://redis.io/commands/script-flush>
fn script_flush(&self) -> Box<Future<Item=(), Error=RedisError>> {
commands::script_flush(&self.inner)
}

/// Returns information about the existence of the scripts in the script cache.
///
/// This command accepts one or more SHA1 digests and returns a list of ones or zeros to signal if the scripts are already defined or not inside the script cache.
///
/// <https://redis.io/commands/script-exists>
fn script_exists<S: Into<MultipleKeys>>(&self, sha1: S) -> Box<Future<Item=Vec<bool>, Error=RedisError>> {
commands::script_exists(&self.inner, sha1)
}

/// Evaluates a script cached on the server side by its SHA1 digest.
///
/// Scripts are cached on the server side using the SCRIPT LOAD command.
///
/// <https://redis.io/commands/evalsha>
fn evalsha<S: Into<String>, K: Into<MultipleKeys>, V: Into<MultipleValues>>(&self, sha1: S, keys: K, args: V) -> Box<Future<Item=Vec<RedisValue>, Error=RedisError>> {
commands::evalsha(&self.inner, sha1, keys, args)
}

/// Adds the specified geospatial items (latitude, longitude, name) to the specified key.
///
/// <https://redis.io/commands/geoadd>
fn geoadd<K: Into<RedisKey>, V: Into<MultipleGeoValues>>(&self, key: K, values: V) -> Box<Future<Item=usize, Error=RedisError>> {
commands::geoadd(&self.inner, key, values)
}

/// Return valid Geohash strings representing the position of one or more elements in a sorted set value representing a geospatial index.
///
/// <https://redis.io/commands/geohash>
fn geohash<K: Into<RedisKey>, V: Into<MultipleValues>>(&self, key: K, values: V) -> Box<Future<Item=Vec<String>, Error=RedisError>> {
commands::geohash(&self.inner, key, values)
}

/// Return the positions (longitude,latitude) of all the specified members of the geospatial index represented by the sorted set at key.
///
/// <https://redis.io/commands/geopos>
fn geopos<K: Into<RedisKey>, V: Into<MultipleValues>>(&self, key: K, values: V) -> Box<Future<Item=Vec<Option<(Longitude, Latitude)>>, Error=RedisError>> {
commands::geopos(&self.inner, key, values)
}

/// Return the distance between two members in the geospatial index represented by the sorted set.
///
/// <https://redis.io/commands/geodist>
fn geodist<K: Into<RedisKey>, M: Into<RedisValue>, N: Into<RedisValue>>(&self, key: K, member1: M, member2: N, unit: Option<GeoUnit>) -> Box<Future<Item=Option<f64>, Error=RedisError>> {
commands::geodist(&self.inner, key, member1, member2, unit)
}

/// Return the members of a sorted set populated with geospatial information using GEOADD, which are within the borders of the area specified with the center location and the maximum distance from the center (the radius).
///
/// <https://redis.io/commands/georadius>
fn georadius<K: Into<RedisKey>>(&self, key: K, longitude: Longitude, latitude: Latitude, radius: f64, unit: GeoUnit,
withcoord: bool, withdist: bool, withhash: bool, count: Option<usize>,
order: Option<GeoOrdering>, store: Option<String>, storedist: Option<String>)
-> Box<Future<Item=Vec<RedisValue>, Error=RedisError>>
Copy link

@RicoGit RicoGit Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use rustfmt? It's brilliant tool.

{
commands::georadius(&self.inner, key, longitude, latitude, radius, unit, withcoord, withdist, withhash, count, order, store, storedist)
}

/// This command is exactly like GEORADIUS with the sole difference that instead of taking, as the center of the area to query, a longitude and latitude value, it takes the name of a member already existing inside the geospatial index represented by the sorted set.
///
/// <https://redis.io/commands/georadiusbymember>
fn georadiusbymember<K: Into<RedisKey>, V: Into<RedisValue>>(&self, key: K, member: V, radius: f64, unit: GeoUnit,
withcoord: bool, withdist: bool, withhash: bool, count: Option<usize>,
order: Option<GeoOrdering>, store: Option<String>, storedist: Option<String>)
-> Box<Future<Item=Vec<RedisValue>, Error=RedisError>>
{
commands::georadiusbymember(&self.inner, key, member, radius, unit, withcoord, withdist, withhash, count, order, store, storedist)
}

}


Expand Down
Loading