Skip to content

Commit

Permalink
Merge pull request #8 from tompro/develop
Browse files Browse the repository at this point in the history
Redis 0.20.0 and REVRANGE commands
  • Loading branch information
tompro authored Feb 28, 2021
2 parents 5075417 + c872a4f commit 47e6d94
Show file tree
Hide file tree
Showing 10 changed files with 530 additions and 27 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redis_ts"
version = "0.3.0"
version = "0.4.0"
authors = ["protom <[email protected]>"]
keywords = ["redis", "database"]
description = "API for Redis time series types."
Expand All @@ -13,7 +13,7 @@ edition = "2018"
exclude = ["docker"]

[dependencies]
redis = { version = "0.19.0", optional = true }
redis = { version = "^0.20.0", optional = true }

[features]
default = ['redis']
Expand All @@ -32,3 +32,6 @@ required-features = ['async-std-comp']
[[test]]
name = "test_async_tokio_commands"
required-features = ['tokio-comp']

[package.metadata.docs.rs]
all-features = true
41 changes: 41 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[tasks.publish]
description = "Publish to crates.io"
dependencies = ["gh_checks"]
command = "cargo"
args = ["publish", "--all-features"]

[tasks.gh_checks]
dependencies = [
"cargo_check",
"test",
"check_fmt",
"clippy"
]

[tasks.cargo_check]
description = "Runs cargo check"
command = "cargo"
args = ["check"]

[tasks.check_fmt]
description = "Runs fmt in check mode"
install_crate = "rustfmt"
command = "cargo"
args = ["fmt", "--all", "--", "--check"]

[tasks.test]
description = "Runs tests with all features"
command = "cargo"
args = ["test", "--all-features"]

[tasks.doc]
description = "Generates docs with all features"
command = "cargo"
args = ["doc", "--all-features"]

[tasks.clippy]
description = "Runs clippy"
install_crate = "clippy"
command = "cargo"
args = ["clippy", "--", "-D warnings"]

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# redis_ts

[![crates.io](https://img.shields.io/badge/crates.io-v0.3.0-orange)](https://crates.io/crates/redis_ts)
[![crates.io](https://img.shields.io/badge/crates.io-v0.4.0-orange)](https://crates.io/crates/redis_ts)
![Continuous integration](https://github.com/tompro/redis_ts/workflows/Continuous%20integration/badge.svg)

redis_ts provides a small trait with extension functions for the
Expand All @@ -10,12 +10,13 @@ a [redis module](https://oss.redislabs.com/redistimeseries). Time
series commands are available as synchronous and asynchronous versions.

The crate is called `redis_ts` and you can depend on it via cargo. You will
also need redis in your dependencies.
also need redis in your dependencies. It has been tested agains redis 0.20.0
but should work with versions higher than that.

```ini
[dependencies]
redis = "0.19.0"
redis_ts = "0.3.0"
redis = "0.20.0"
redis_ts = "0.4.0"
```

Or via git:
Expand All @@ -28,8 +29,8 @@ also need redis in your dependencies.
With async feature inherited from the [redis](https://docs.rs/redis) crate (either: 'async-std-comp' or 'tokio-comp):
```ini
[dependencies]
redis = "0.19.0"
redis_ts = { version = "0.3.0", features = ['tokio-comp'] }
redis = "0.20.0"
redis_ts = { version = "0.4.0", features = ['tokio-comp'] }
```
## Synchronous usage
Expand Down
120 changes: 114 additions & 6 deletions src/async_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ pub trait AsyncTsCommands: ConnectionLike + Send + Sized {
Box::pin(async move { cmd("TS.MGET").arg(filter_options).query_async(self).await })
}

/// Executes a redis time series range query.
fn ts_range<
#[doc(hidden)]
fn range<
'a,
K: ToRedisArgs + Send + Sync + 'a,
FTS: ToRedisArgs + Send + Sync + 'a,
Expand All @@ -317,22 +317,77 @@ pub trait AsyncTsCommands: ConnectionLike + Send + Sized {
V: std::marker::Copy + FromRedisValue,
>(
&'a mut self,
command: &str,
key: K,
from_timestamp: FTS,
to_timestamp: TTS,
count: Option<C>,
aggregation_type: Option<TsAggregationType>,
) -> RedisFuture<TsRange<TS, V>> {
let mut c = cmd("TS.RANGE");
let mut c = cmd(command);
c.arg(key).arg(from_timestamp).arg(to_timestamp);
if let Some(ct) = count {
c.arg("COUNT").arg(ct);
}
Box::pin(async move { c.arg(aggregation_type).query_async(self).await })
}

/// Executes multiple redis time series range queries.
fn ts_mrange<
/// Executes a redis time series range query.
fn ts_range<
'a,
K: ToRedisArgs + Send + Sync + 'a,
FTS: ToRedisArgs + Send + Sync + 'a,
TTS: ToRedisArgs + Send + Sync + 'a,
C: ToRedisArgs + Send + Sync + 'a,
TS: std::marker::Copy + FromRedisValue,
V: std::marker::Copy + FromRedisValue,
>(
&'a mut self,
key: K,
from_timestamp: FTS,
to_timestamp: TTS,
count: Option<C>,
aggregation_type: Option<TsAggregationType>,
) -> RedisFuture<TsRange<TS, V>> {
self.range(
"TS.RANGE",
key,
from_timestamp,
to_timestamp,
count,
aggregation_type,
)
}

/// Executes a redis time series revrange query.
fn ts_revrange<
'a,
K: ToRedisArgs + Send + Sync + 'a,
FTS: ToRedisArgs + Send + Sync + 'a,
TTS: ToRedisArgs + Send + Sync + 'a,
C: ToRedisArgs + Send + Sync + 'a,
TS: std::marker::Copy + FromRedisValue,
V: std::marker::Copy + FromRedisValue,
>(
&'a mut self,
key: K,
from_timestamp: FTS,
to_timestamp: TTS,
count: Option<C>,
aggregation_type: Option<TsAggregationType>,
) -> RedisFuture<TsRange<TS, V>> {
self.range(
"TS.REVRANGE",
key,
from_timestamp,
to_timestamp,
count,
aggregation_type,
)
}

#[doc(hidden)]
fn mrange<
'a,
FTS: ToRedisArgs + Send + Sync + 'a,
TTS: ToRedisArgs + Send + Sync + 'a,
Expand All @@ -341,13 +396,14 @@ pub trait AsyncTsCommands: ConnectionLike + Send + Sized {
V: std::default::Default + FromRedisValue + Copy,
>(
&mut self,
command: &str,
from_timestamp: FTS,
to_timestamp: TTS,
count: Option<C>,
aggregation_type: Option<TsAggregationType>,
filter_options: TsFilterOptions,
) -> RedisFuture<TsMrange<TS, V>> {
let mut c = cmd("TS.MRANGE");
let mut c = cmd(command);
c.arg(from_timestamp).arg(to_timestamp);
if let Some(ct) = count {
c.arg("COUNT").arg(ct);
Expand All @@ -356,6 +412,58 @@ pub trait AsyncTsCommands: ConnectionLike + Send + Sized {
Box::pin(async move { c.query_async(self).await })
}

/// Executes multiple redis time series range queries.
fn ts_mrange<
'a,
FTS: ToRedisArgs + Send + Sync + 'a,
TTS: ToRedisArgs + Send + Sync + 'a,
C: ToRedisArgs + Send + Sync + 'a,
TS: std::default::Default + FromRedisValue + Copy,
V: std::default::Default + FromRedisValue + Copy,
>(
&mut self,
from_timestamp: FTS,
to_timestamp: TTS,
count: Option<C>,
aggregation_type: Option<TsAggregationType>,
filter_options: TsFilterOptions,
) -> RedisFuture<TsMrange<TS, V>> {
self.mrange(
"TS.MRANGE",
from_timestamp,
to_timestamp,
count,
aggregation_type,
filter_options,
)
}

/// Executes multiple redis time series revrange queries.
fn ts_mrevrange<
'a,
FTS: ToRedisArgs + Send + Sync + 'a,
TTS: ToRedisArgs + Send + Sync + 'a,
C: ToRedisArgs + Send + Sync + 'a,
TS: std::default::Default + FromRedisValue + Copy,
V: std::default::Default + FromRedisValue + Copy,
>(
&mut self,
from_timestamp: FTS,
to_timestamp: TTS,
count: Option<C>,
aggregation_type: Option<TsAggregationType>,
filter_options: TsFilterOptions,
) -> RedisFuture<TsMrange<TS, V>> {
self.mrange(
"TS.MREVRANGE",
from_timestamp,
to_timestamp,
count,
aggregation_type,
filter_options,
)
}

/// Returns a filtered list of redis time series keys.
fn ts_queryindex(&mut self, filter_options: TsFilterOptions) -> RedisFuture<Vec<String>> {
Box::pin(async move {
Expand Down
Loading

0 comments on commit 47e6d94

Please sign in to comment.